Check-in [cebb4a9b01]

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Refactor the class loading a bit; Store resource index of the class; Base for moving around code.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: cebb4a9b012af6f13f9ecd2c0b05284c1df1c22b
User & Date: stephanie.gawroriski 2019-10-27 16:26:12
Context
2019-10-27
16:28
Remove deprecated code. check-in: 83d6e7ccd2 user: stephanie.gawroriski tags: trunk
16:26
Refactor the class loading a bit; Store resource index of the class; Base for moving around code. check-in: cebb4a9b01 user: stephanie.gawroriski tags: trunk
2019-10-26
21:09
Logic to allocate the data needed to store the ClassInfo data. check-in: 905f13a21e user: stephanie.gawroriski tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to runt/klib/supervisor/cc/squirreljme/jvm/ClassInfo.java.

68
69
70
71
72
73
74



75
76
77
78
79
80
81
..
87
88
89
90
91
92
93

94
95
96
97
98
99
100
101
102
103
104
105
106
...
114
115
116
117
118
119
120

121
122
123
	
	/** Virtual invoke VTable pool entries. */
	public final int[] vtablepool;
	
	/** The pointer to the constant pool of this class. */
	public final int pool;
	



	/**
	 * Class information constructor.
	 *
	 * @param __sp Self pointer.
	 * @param __fl Class information flags.
	 * @param __minip Pointer to the hardware class data in ROM.
	 * @param __namep The name pointer.
................................................................................
	 * @param __scl The super class data.
	 * @param __icl Interface classes.
	 * @param __ccl Component class.
	 * @param __cop Pointer to the class object.
	 * @param __vtv Virtual invoke VTable address.
	 * @param __vtp Virtual invoke VTable pool addresses.
	 * @param __pool The pointer to the class constant pool.

	 * @since 2019/04/26
	 */
	public ClassInfo(int __sp, int __fl, int __minip, int __namep, int __sz,
		int __bz, int __no, int __dim, int __csz, ClassInfo __scl,
		ClassInfo[] __icl, ClassInfo __ccl, Class<?> __cop, int[] __vtv,
		int[] __vtp, int __pool)
	{
		// Always implicitly set magic
		this.magic = MAGIC_NUMBER;
		
		// Set
		this.selfptr = __sp;
		this.flags = __fl;
................................................................................
		this.superclass = __scl;
		this.interfaceclasses = (__icl == null ? new ClassInfo[0] : __icl);
		this.componentclass = __ccl;
		this.classobjptr = __cop;
		this.vtablevirtual = (__vtv == null ? new int[0] : __vtv);
		this.vtablepool = (__vtp == null ? new int[0] : __vtp);
		this.pool = __pool;

	}
}








>
>
>







 







>





|







 







>



68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
..
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
...
118
119
120
121
122
123
124
125
126
127
128
	
	/** Virtual invoke VTable pool entries. */
	public final int[] vtablepool;
	
	/** The pointer to the constant pool of this class. */
	public final int pool;
	
	/** The JAR this class is a part of. */
	public final int jardx;
	
	/**
	 * Class information constructor.
	 *
	 * @param __sp Self pointer.
	 * @param __fl Class information flags.
	 * @param __minip Pointer to the hardware class data in ROM.
	 * @param __namep The name pointer.
................................................................................
	 * @param __scl The super class data.
	 * @param __icl Interface classes.
	 * @param __ccl Component class.
	 * @param __cop Pointer to the class object.
	 * @param __vtv Virtual invoke VTable address.
	 * @param __vtp Virtual invoke VTable pool addresses.
	 * @param __pool The pointer to the class constant pool.
	 * @param __jardx The JAR Index.
	 * @since 2019/04/26
	 */
	public ClassInfo(int __sp, int __fl, int __minip, int __namep, int __sz,
		int __bz, int __no, int __dim, int __csz, ClassInfo __scl,
		ClassInfo[] __icl, ClassInfo __ccl, Class<?> __cop, int[] __vtv,
		int[] __vtp, int __pool, int __jardx)
	{
		// Always implicitly set magic
		this.magic = MAGIC_NUMBER;
		
		// Set
		this.selfptr = __sp;
		this.flags = __fl;
................................................................................
		this.superclass = __scl;
		this.interfaceclasses = (__icl == null ? new ClassInfo[0] : __icl);
		this.componentclass = __ccl;
		this.classobjptr = __cop;
		this.vtablevirtual = (__vtv == null ? new int[0] : __vtv);
		this.vtablepool = (__vtp == null ? new int[0] : __vtp);
		this.pool = __pool;
		this.jardx = __jardx;
	}
}

Changes to runt/klib/supervisor/cc/squirreljme/jvm/lib/ClassPath.java.

199
200
201
202
203
204
205
206


207










		int rv = this.resourceFindIn(__name, __in);
		if (rv >= 0)
			return rv;
		
		// Then locate it in any class library
		return this.resourceFind(__name);
	}
}




















|
>
>
|
>
>
>
>
>
>
>
>
>
>
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
		int rv = this.resourceFindIn(__name, __in);
		if (rv >= 0)
			return rv;
		
		// Then locate it in any class library
		return this.resourceFind(__name);
	}
	
	/** 
	 * Returns the JAR index of the given resource index.
	 *
	 * @param __rcid The resource index.
	 * @return The JAR index of the given resource.
	 * @since 2019/10/27
	 */
	public static final int resourceIndexToJarIndex(int __rcid)
	{
		return (__rcid & _JAR_MASK) >>> _INDEX_SHIFT;
	}
}

Changes to runt/klib/supervisor/cc/squirreljme/jvm/task/Task.java.

118
119
120
121
122
123
124


125
126
127
128
129
130

131
132
133
134

135

136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
	
	/**
	 * Loads the given class.
	 *
	 * @param __cl The class to load.
	 * @return The pointer to the class information.
	 * @throws NullPointerException On null arguments.


	 * @throws TaskVirtualMachineError If there is something wrong with the
	 * task virtual machine.
	 * @since 2019/10/13
	 */
	public final TaskClass loadClass(String __cl)
		throws NullPointerException, TaskVirtualMachineError

	{
		if (__cl == null)
			throw new NullPointerException("NARG");
		

		TaskClass rv;

		
		// Try to find already initialized class
		HashMap<String, TaskClass> classes = this._classes;
		synchronized (this)
		{
			// Already made?
			rv = classes.get(__cl);
			if (rv != null)
				return rv;
			
			// Otherwise store and set it
			classes.put(__cl, (rv = new TaskClass()));
		}
		
		// Needed to search for classes
		ClassPath classpath = this.classpath;
		
		// {@squirreljme.error SV0l Task does has ClassInfo in its
		// class path.}
		int cidx = classpath.resourceClassFind("cc/squirreljme/jvm/ClassInfo");
		if (cidx < 0)
			throw new TaskVirtualMachineError("SV0l");
		
		// Get parser for this class, because we need its info
		ClassFileParser ciparser = new ClassFileParser(
			classpath.resourceData(cidx));
		
		// Need to allocate class data
		TaskAllocator allocator = this.allocator;
		
		// Allocate the space needed to store the class information
		int infopointer = allocator.allocateObject(Constants.OBJECT_BASE_SIZE +
			ciparser.fieldSize(false));
		rv._infopointer = infopointer;
		
		throw new todo.TODO();
	}
	
	/**
	 * Loads the in-memory class information for the given class.
	 *
	 * @param __cl The class to load.
	 * @return The loaded class information or {@code null} if it is not found.







>
>





|
>




>

>










|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<
<
<
<
<
<
<
<
<
<
<







118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165











166
167
168
169
170
171
172
	
	/**
	 * Loads the given class.
	 *
	 * @param __cl The class to load.
	 * @return The pointer to the class information.
	 * @throws NullPointerException On null arguments.
	 * @throws TaskNoSuchClassException If the task does not have the specified
	 * class.
	 * @throws TaskVirtualMachineError If there is something wrong with the
	 * task virtual machine.
	 * @since 2019/10/13
	 */
	public final TaskClass loadClass(String __cl)
		throws NullPointerException, TaskNoSuchClassException,
			TaskVirtualMachineError
	{
		if (__cl == null)
			throw new NullPointerException("NARG");
		
		// Needed to search for classes
		TaskClass rv;
		ClassPath classpath = this.classpath;
		
		// Try to find already initialized class
		HashMap<String, TaskClass> classes = this._classes;
		synchronized (this)
		{
			// Already made?
			rv = classes.get(__cl);
			if (rv != null)
				return rv;
			
			// {@squirreljme.error SV0m The specified class does not exist.
			// (The class which does not exist)}
			int cldx = classpath.resourceClassFind(__cl);
			if (cldx < 0)
				throw new TaskNoSuchClassException("SV0m " + __cl);
			
			// Setup new one and store it
			classes.put(__cl, (rv = new TaskClass(cldx)));
			
			// Pre-initialize the class
			rv.initializeClassInfoSetup(this);
		}
		
		// Perform post initialization as needed
		return rv.initializeClassInfo(this);











	}
	
	/**
	 * Loads the in-memory class information for the given class.
	 *
	 * @param __cl The class to load.
	 * @return The loaded class information or {@code null} if it is not found.

Changes to runt/klib/supervisor/cc/squirreljme/jvm/task/TaskClass.java.

12
13
14
15
16
17
18



19
20
21
22
23
24
25
26
27

28
29
30
31

32
33


34










































































/**
 * This represents a class of a task.
 *
 * @since 2019/10/19
 */
public final class TaskClass
{



	/** The allocated class information. */
	int _infopointer;
	
	/** The run-time constant pool pointer. */
	int _pool;
	
	/**
	 * Initializes the class container.
	 *

	 * @since 2019/10/19
	 */
	public TaskClass()
	{

	}
}




















































































>
>
>

|


|




>


|

>

|
>
>
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
/**
 * This represents a class of a task.
 *
 * @since 2019/10/19
 */
public final class TaskClass
{
	/** The index of the class in the resource table. */
	protected final int resourceindex;
	
	/** The allocated class information. */
	private int _infopointer;
	
	/** The run-time constant pool pointer. */
	private int _pool;
	
	/**
	 * Initializes the class container.
	 *
	 * @param __cldx The class path resource index.
	 * @since 2019/10/19
	 */
	public TaskClass(int __cldx)
	{
		this.resourceindex = __cldx;
	}
	
	/**
	 * Returns the info pointer.
	 *
	 * @return The info pointer.
	 * @throws TaskVirtualMachineError If the info pointer was not set.
	 * @since 2019/10/27
	 */
	public final int infoPointer()
		throws TaskVirtualMachineError
	{
		int rv = this._infopointer;
		
		// {@squirreljme.error SV0n Class information pointer not set.}
		if (rv == 0)
			throw new TaskVirtualMachineError("SV0n");
		
		return rv;
	}
	
	/**
	 * Performs the main initialization of this class.
	 *
	 * @param __task The creating task.
	 * @return {@code this}.
	 * @throws NullPointerException On null arguments.
	 * @since 2019/10/27
	 */
	public final TaskClass initializeClassInfo(Task __task)
		throws NullPointerException
	{
		if (__task == null)
			throw new NullPointerException("NARG");
		
		throw new todo.TODO();
	}
	
	/**
	 * Performs enough setup of the class info to rever to it when the
	 * class table is not locked.
	 *
	 * @param __task The creating task.
	 * @return {@code this}.
	 * @throws NullPointerException On null arguments.
	 * @since 2019/10/27
	 */
	public final TaskClass initializeClassInfoSetup(Task __task)
		throws NullPointerException
	{
		if (__task == null)
			throw new NullPointerException("NARG");
		
		throw new todo.TODO();
		
		/*
		// {@squirreljme.error SV0l Task does not have ClassInfo in its
		// class path.}
		int cidx = classpath.resourceClassFind("cc/squirreljme/jvm/ClassInfo");
		if (cidx < 0)
			throw new TaskVirtualMachineError("SV0l");
		
		// Get parser for the class info, because we need its info
		ClassFileParser ciparser = new ClassFileParser(
			classpath.resourceData(cidx));
		
		// Need to allocate class data
		TaskAllocator allocator = this.allocator;
		
		// Allocate the space needed to store the class information
		int infopointer = allocator.allocateObject(Constants.OBJECT_BASE_SIZE +
			ciparser.fieldSize(false));
		rv._infopointer = infopointer;
		
		throw new todo.TODO();
		*/
	}
}

Added runt/klib/supervisor/cc/squirreljme/jvm/task/TaskNoSuchClassException.java.































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
// -*- Mode: Java; indent-tabs-mode: t; tab-width: 4 -*-
// ---------------------------------------------------------------------------
// Multi-Phasic Applications: SquirrelJME
//     Copyright (C) Stephanie Gawroriski <xer@multiphasicapps.net>
// ---------------------------------------------------------------------------
// SquirrelJME is under the GNU General Public License v3+, or later.
// See license.mkd for licensing and copyright information.
// ---------------------------------------------------------------------------

package cc.squirreljme.jvm.task;

/**
 * This is thrown when a class does not exist for a task.
 *
 * @since 2019/10/27
 */
public class TaskNoSuchClassException
	extends TaskException
{
	/**
	 * Initializes the exception with no message or cause.
	 *
	 * @since 2019/10/21
	 */
	public TaskNoSuchClassException()
	{
	}
	
	/**
	 * Initializes the exception with the given message and no cause.
	 *
	 * @param __m The message.
	 * @since 2019/10/27
	 */
	public TaskNoSuchClassException(String __m)
	{
		super(__m);
	}
	
	/**
	 * Initializes the exception with the given message and cause.
	 *
	 * @param __m The message.
	 * @param __t The cause.
	 * @since 2019/10/27
	 */
	public TaskNoSuchClassException(String __m, Throwable __t)
	{
		super(__m, __t);
	}
	
	/**
	 * Initializes the exception with the given cause and no message.
	 *
	 * @param __t The cause.
	 * @since 2019/10/27
	 */
	public TaskNoSuchClassException(Throwable __t)
	{
		super(__t);
	}
}

Changes to runt/libs/tool-jarfile/dev/shadowtail/jarfile/LoadedClassInfo.java.

450
451
452
453
454
455
456






457
458
459
460
461
462
463
							initializer.memWriteInt(Modifier.RAM_OFFSET,
								xp + Constants.OBJECT_CLASS_OFFSET,
								bootstrap.findClass(
								"[Lcc/squirreljme/jvm/ClassInfo;").
								infoPointer());
						}
						break;






					
					// Magic number
				case "magic:I":
					initializer.memWriteInt(
						wp, ClassInfo.MAGIC_NUMBER);
					break;
					







>
>
>
>
>
>







450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
							initializer.memWriteInt(Modifier.RAM_OFFSET,
								xp + Constants.OBJECT_CLASS_OFFSET,
								bootstrap.findClass(
								"[Lcc/squirreljme/jvm/ClassInfo;").
								infoPointer());
						}
						break;
					
					// The JAR index, always zero for the bootstrap
				case "jardx:I":
					initializer.memWriteInt(
						wp, 0);
					break;
					
					// Magic number
				case "magic:I":
					initializer.memWriteInt(
						wp, ClassInfo.MAGIC_NUMBER);
					break;