Check-in [b623c22b59]

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

Overview
Comment:Minor work.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:b623c22b5934e92a4c083c8cb5a498dc88a7191f
User & Date: stephanie.gawroriski 2019-06-15 20:31:19
Context
2019-06-15
20:40
Add memset() system call to possibly and more quickly wipe memory. check-in: d13dde95bf user: stephanie.gawroriski tags: trunk
20:31
Minor work. check-in: b623c22b59 user: stephanie.gawroriski tags: trunk
14:39
Make the debug stuff more descriptive. check-in: 3d3ad815fb user: stephanie.gawroriski tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

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

122
123
124
125
126
127
128


129

130
131
132
133
134
135
136
	 *
	 * @param __p The pointer to free.
	 * @since 2019/05/27
	 */
	static final void free(int __p)
	{
		if (__p == 0 || __p == Constants.BAD_MAGIC)


			throw new VirtualMachineError();

		
		// Determine the seeker position for this chunk
		int seeker = __p - CHUNK_LENGTH;
		
		// Read chunk properties
		int csz = Assembly.memReadInt(seeker, CHUNK_SIZE_OFFSET),
			cnx = Assembly.memReadInt(seeker, CHUNK_NEXT_OFFSET);







>
>

>







122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
	 *
	 * @param __p The pointer to free.
	 * @since 2019/05/27
	 */
	static final void free(int __p)
	{
		if (__p == 0 || __p == Constants.BAD_MAGIC)
		{
			Assembly.breakpoint();
			throw new VirtualMachineError();
		}
		
		// Determine the seeker position for this chunk
		int seeker = __p - CHUNK_LENGTH;
		
		// Read chunk properties
		int csz = Assembly.memReadInt(seeker, CHUNK_SIZE_OFFSET),
			cnx = Assembly.memReadInt(seeker, CHUNK_NEXT_OFFSET);

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

20
21
22
23
24
25
26



































27
28
29
30
31
32
33
..
39
40
41
42
43
44
45





46
47
48
49
50
51
52
	 * Not used.
	 *
	 * @since 2019/05/25
	 */
	private Bootstrap()
	{
	}



































	
	/**
	 * Entry point for the bootstrap.
	 *
	 * @param __rambase The base RAM address.
	 * @param __ramsize The size of RAM.
	 * @param __rombase Base address of the ROM (for offset calculation).
................................................................................
	static final void __start(int __rambase, int __ramsize,
		int __rombase, int __romsize, int __confbase, int __confsize)
	{
		// Initialize the RAM links to setup dirty bits and initialize the
		// last block of memory with anything that remains. This makes it so
		// the RAM is actually useable.
		Allocator.__initRamLinks(__rambase, __ramsize);





		
		String qx = "Hello?";
		String qy = "Love you!";
		String qz = "Is this working?";
		todo.DEBUG.note("%s %s %s", qx, qy, qz);
		Assembly.breakpoint();
		







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







 







>
>
>
>
>







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
..
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
	 * Not used.
	 *
	 * @since 2019/05/25
	 */
	private Bootstrap()
	{
	}
	
	/**
	 * Performs a self test of the virtual machine to make sure things are
	 * operating correctly!
	 *
	 * @param __rambase The base RAM address.
	 * @param __ramsize The size of RAM.
	 * @param __rombase Base address of the ROM (for offset calculation).
	 * @param __romsize The size of ROM.
	 * @param __confbase The configuration memory base.
	 * @param __confsize The configuration memory size.
	 */
	public static final void selfTest(int __rambase, int __ramsize,
		int __rombase, int __romsize, int __confbase, int __confsize)
	{
		// Banner for self test
		todo.DEBUG.note("SquirrelJME 0.3.0 Self-Test");
		
		// Could throw any kind of exception
		try
		{
			// I have had a bunch of issues with subsequent jvmLoadString()s
			// failing with calling bad pointers and such. So this is a basic
			// test to ensure that things are working.
			todo.DEBUG.note("%s %s?", "Triple jvmLoadString()?", "Okay!");
		}
		
		// Exception was caught??
		catch (Throwable t)
		{
			todo.DEBUG.code('X', 'X', Assembly.memReadInt(
				Assembly.objectToPointer(t), Constants.OBJECT_CLASS_OFFSET));
			Assembly.breakpoint();
		}
	}
	
	/**
	 * Entry point for the bootstrap.
	 *
	 * @param __rambase The base RAM address.
	 * @param __ramsize The size of RAM.
	 * @param __rombase Base address of the ROM (for offset calculation).
................................................................................
	static final void __start(int __rambase, int __ramsize,
		int __rombase, int __romsize, int __confbase, int __confsize)
	{
		// Initialize the RAM links to setup dirty bits and initialize the
		// last block of memory with anything that remains. This makes it so
		// the RAM is actually useable.
		Allocator.__initRamLinks(__rambase, __ramsize);
		
		// Perform a self-test of the JVM environment to make sure things
		// are working
		Bootstrap.selfTest(__rambase, __ramsize, __rombase, __romsize,
			__confbase, __confsize);
		
		String qx = "Hello?";
		String qy = "Love you!";
		String qz = "Is this working?";
		todo.DEBUG.note("%s %s %s", qx, qy, qz);
		Assembly.breakpoint();
		

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

34
35
36
37
38
39
40


41

42
43
44
45
46
47
48
..
70
71
72
73
74
75
76


77

78
79
80
81
82
83
84
..
98
99
100
101
102
103
104


105

106
107
108
109


110

111
112
113
114
115
116
117
...
168
169
170
171
172
173
174


175

176
177
178
179
180
181
182
...
185
186
187
188
189
190
191


192

193
194
195
196
197
198
199
...
204
205
206
207
208
209
210


211

212
213
214
215
216
217
218
219
220
221
222
223


224

225
226
227
228
229
230
231
232
233
234


235

236
237
238
239
240
241
242
243
244
245
246
247
248


249

250
251
252
253
254
255
256
...
265
266
267
268
269
270
271


272

273
274
275
276
277
278
279
...
298
299
300
301
302
303
304


305

306
307
308


309

310
311
312
313
314
315
316
...
370
371
372
373
374
375
376


377

378
379
380
381
382
383
384
...
386
387
388
389
390
391
392


393

394
395
396
397
398
399
400
...
403
404
405
406
407
408
409


410

411
412
413


414

415
416
417
418
419
420
421
...
443
444
445
446
447
448
449


450

451
452
453


454

455
456
457
458
459
460
461
	 * be returned, otherwise {@code 0} will.
	 * @since 2019/04/27
	 */
	public static final int jvmCanArrayStore(int __p, int __v)
	{
		// Access of invalid object?
		if (__p == Constants.BAD_MAGIC || __v == Constants.BAD_MAGIC)


			throw new VirtualMachineError();

		
		// Can always store null values
		if (__v == 0)
			return 1;
		
		// Load the component for this array
		ClassInfo pci = Assembly.pointerToClassInfo(
................................................................................
	 * array.
	 * @since 2019/04/27
	 */
	public static final int jvmComponentType(int __clid)
	{
		// Access of invalid class?
		if (__clid == Constants.BAD_MAGIC)


			throw new VirtualMachineError();

		
		Assembly.breakpoint();
		throw new todo.TODO();
	}
	
	/**
	 * Performs aggressive garbage collection of the JVM heap to free as much
................................................................................
	 * @param __p The object to garbage collect.
	 * @since 2019/04/25
	 */
	public static final void jvmGarbageCollectObject(int __p)
	{
		// Access of invalid object?
		if (__p == 0 || __p == Constants.BAD_MAGIC)


			throw new VirtualMachineError();

		
		// Attempt to garbage collect object with no class or is invalid
		int pcl = Assembly.memReadInt(__p, Constants.OBJECT_CLASS_OFFSET);
		if (pcl == 0 || pcl == Constants.BAD_MAGIC)


			throw new VirtualMachineError();

		
		// Debug
		todo.DEBUG.code('G', 'C', __p);
		
		// Get class info for this type
		ClassInfo pinfo = Assembly.pointerToClassInfo(pcl);
		
................................................................................
	 * @return The pointer to the code to be invoked.
	 * @since 2019/04/30
	 */
	public static final int jvmInterfacePointer(int __p, int __icl, int __mdx)
	{
		// Access of invalid object?
		if (__p == Constants.BAD_MAGIC)


			throw new VirtualMachineError();

		
		Assembly.breakpoint();
		throw new todo.TODO();
	}
	
	/**
	 * Checks whether the given pointer is an array.
................................................................................
	 * @return Either {@code 1} if it is an array or {@code 0} if it is not.
	 * @since 2019/04/27
	 */
	public static final int jvmIsArray(int __p)
	{
		// Access of invalid object?
		if (__p == Constants.BAD_MAGIC)


			throw new VirtualMachineError();

		
		Assembly.breakpoint();
		throw new todo.TODO();
	}
	
	/**
	 * Checks whether the given pointer is an instance of the given class.
................................................................................
	 * it is not.
	 * @since 2019/04/22
	 */
	public static final int jvmIsInstance(int __p, int __cldx)
	{
		// Access of invalid object?
		if (__p == Constants.BAD_MAGIC)


			throw new VirtualMachineError();

		
		// Not instance of null class
		if (__p == 0)
			return 0;
		
		// If the object's class type is a direct match then quickly return
		int pcl = Assembly.memReadInt(__p, Constants.OBJECT_CLASS_OFFSET);
		if (pcl == __cldx)
			return 1;
		
		// Corrupted object?
		if (pcl == 0 || pcl == Constants.BAD_MAGIC)


			throw new VirtualMachineError();

		
		// Scan through super classes and check
		ClassInfo mine = Assembly.pointerToClassInfo(pcl);
		for (ClassInfo seek = mine; seek != null; seek = seek.superclass)
		{
			// Get self pointer
			int selfptr = seek.selfptr;
			
			// Make sure we are not reading bad memory
			if (selfptr == Constants.BAD_MAGIC)


				throw new VirtualMachineError();

			
			// Same as this one?
			if (selfptr == __cldx)
				return 1;
			
			// See if our class or any of our super class implemented
			// interfaces matches the target class
			for (ClassInfo xface : mine.interfaceclasses)
			{
				int ifaceptr = xface.selfptr;
				
				// Make sure we are not reading bad memory
				if (ifaceptr == Constants.BAD_MAGIC)


					throw new VirtualMachineError();

				
				// Is a match?
				if (ifaceptr == __cldx)
					return 1;
			}
		}
		
................................................................................
	 * @param __cldx The class index pointer.
	 * @since 2019/05/26
	 */
	public static final Class<?> jvmLoadClass(int __cldx)
	{
		// Access of invalid class?
		if (__cldx == Constants.BAD_MAGIC)


			throw new VirtualMachineError();

		
		Assembly.breakpoint();
		throw new todo.TODO();
	}
	
	/**
	 * Loads a string from memory and returns an `intern()` string value.
................................................................................
	public static final String jvmLoadStringNoIntern(int __p)
	{
		// Note
		todo.DEBUG.code('J', 'S', __p);
		
		// Access of invalid object?
		if (__p == Constants.BAD_MAGIC)


			throw new VirtualMachineError();

		
		// Cannot load from a null string
		if (__p == 0)


			throw new VirtualMachineError();

		
		// Read length of the raw bytes
		int rawlen = Assembly.memReadJavaShort(__p, 0) & 0xFFFF;
		
		// Load the string data into bytes
		byte[] bytes = new byte[rawlen];
		for (int i = 0, base = __p + 2; i < rawlen; i++)
................................................................................
	 * @param __p The object to enter.
	 * @since 2019/04/26
	 */
	public static final void jvmMonitorEnter(int __p)
	{
		// Access of invalid object?
		if (__p == Constants.BAD_MAGIC)


			throw new VirtualMachineError();

		
		Assembly.breakpoint();
		throw new todo.TODO();
	}
	
	/**
	 * Exits the monitor for the given object.
................................................................................
	 * @param __p The object to exit.
	 * @since 2019/04/26
	 */
	public static final void jvmMonitorExit(int __p)
	{
		// Access of invalid object?
		if (__p == Constants.BAD_MAGIC)


			throw new VirtualMachineError();

		
		Assembly.breakpoint();
		throw new todo.TODO();
	}
	
	/**
	 * Allocates a new object.
................................................................................
	 * @return The resulting class pointer.
	 * @since 2019/05/24
	 */
	public static final int jvmNew(int __cl)
	{
		// Access of invalid class?
		if (__cl == Constants.BAD_MAGIC)


			throw new VirtualMachineError();

		
		// Cannot allocate a null class
		if (__cl == 0)


			throw new VirtualMachineError();

		
		// Get the class information for the object to allocate
		ClassInfo info = Assembly.pointerToClassInfo(__cl);
		
		// Allocate the memory
		int rv = Allocator.allocate(info.size);
		if (rv == 0)
................................................................................
	 * @since 2019/04/24
	 */
	public static final int jvmNewArray(int __at, int __len)
		throws NegativeArraySizeException, OutOfMemoryError
	{
		// Access of invalid class?
		if (__at == Constants.BAD_MAGIC)


			throw new VirtualMachineError();

		
		// Do not initialize null class
		if (__at == 0)


			throw new VirtualMachineError();

		
		// Cannot allocate negative length
		if (__len < 0)
			throw new NegativeArraySizeException();
		
		// Get the class information for the array we want to allocate
		ClassInfo info = Assembly.pointerToClassInfo(__at);







>
>

>







 







>
>

>







 







>
>

>




>
>

>







 







>
>

>







 







>
>

>







 







>
>

>












>
>

>










>
>

>













>
>

>







 







>
>

>







 







>
>

>



>
>

>







 







>
>

>







 







>
>

>







 







>
>

>



>
>

>







 







>
>

>



>
>

>







34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
..
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
...
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
...
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
...
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
...
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
...
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
...
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
...
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
...
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
...
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
...
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
	 * be returned, otherwise {@code 0} will.
	 * @since 2019/04/27
	 */
	public static final int jvmCanArrayStore(int __p, int __v)
	{
		// Access of invalid object?
		if (__p == Constants.BAD_MAGIC || __v == Constants.BAD_MAGIC)
		{
			Assembly.breakpoint();
			throw new VirtualMachineError();
		}
		
		// Can always store null values
		if (__v == 0)
			return 1;
		
		// Load the component for this array
		ClassInfo pci = Assembly.pointerToClassInfo(
................................................................................
	 * array.
	 * @since 2019/04/27
	 */
	public static final int jvmComponentType(int __clid)
	{
		// Access of invalid class?
		if (__clid == Constants.BAD_MAGIC)
		{
			Assembly.breakpoint();
			throw new VirtualMachineError();
		}
		
		Assembly.breakpoint();
		throw new todo.TODO();
	}
	
	/**
	 * Performs aggressive garbage collection of the JVM heap to free as much
................................................................................
	 * @param __p The object to garbage collect.
	 * @since 2019/04/25
	 */
	public static final void jvmGarbageCollectObject(int __p)
	{
		// Access of invalid object?
		if (__p == 0 || __p == Constants.BAD_MAGIC)
		{
			Assembly.breakpoint();
			throw new VirtualMachineError();
		}
		
		// Attempt to garbage collect object with no class or is invalid
		int pcl = Assembly.memReadInt(__p, Constants.OBJECT_CLASS_OFFSET);
		if (pcl == 0 || pcl == Constants.BAD_MAGIC)
		{
			Assembly.breakpoint();
			throw new VirtualMachineError();
		}
		
		// Debug
		todo.DEBUG.code('G', 'C', __p);
		
		// Get class info for this type
		ClassInfo pinfo = Assembly.pointerToClassInfo(pcl);
		
................................................................................
	 * @return The pointer to the code to be invoked.
	 * @since 2019/04/30
	 */
	public static final int jvmInterfacePointer(int __p, int __icl, int __mdx)
	{
		// Access of invalid object?
		if (__p == Constants.BAD_MAGIC)
		{
			Assembly.breakpoint();
			throw new VirtualMachineError();
		}
		
		Assembly.breakpoint();
		throw new todo.TODO();
	}
	
	/**
	 * Checks whether the given pointer is an array.
................................................................................
	 * @return Either {@code 1} if it is an array or {@code 0} if it is not.
	 * @since 2019/04/27
	 */
	public static final int jvmIsArray(int __p)
	{
		// Access of invalid object?
		if (__p == Constants.BAD_MAGIC)
		{
			Assembly.breakpoint();
			throw new VirtualMachineError();
		}
		
		Assembly.breakpoint();
		throw new todo.TODO();
	}
	
	/**
	 * Checks whether the given pointer is an instance of the given class.
................................................................................
	 * it is not.
	 * @since 2019/04/22
	 */
	public static final int jvmIsInstance(int __p, int __cldx)
	{
		// Access of invalid object?
		if (__p == Constants.BAD_MAGIC)
		{
			Assembly.breakpoint();
			throw new VirtualMachineError();
		}
		
		// Not instance of null class
		if (__p == 0)
			return 0;
		
		// If the object's class type is a direct match then quickly return
		int pcl = Assembly.memReadInt(__p, Constants.OBJECT_CLASS_OFFSET);
		if (pcl == __cldx)
			return 1;
		
		// Corrupted object?
		if (pcl == 0 || pcl == Constants.BAD_MAGIC)
		{
			Assembly.breakpoint();
			throw new VirtualMachineError();
		}
		
		// Scan through super classes and check
		ClassInfo mine = Assembly.pointerToClassInfo(pcl);
		for (ClassInfo seek = mine; seek != null; seek = seek.superclass)
		{
			// Get self pointer
			int selfptr = seek.selfptr;
			
			// Make sure we are not reading bad memory
			if (selfptr == Constants.BAD_MAGIC)
			{
				Assembly.breakpoint();
				throw new VirtualMachineError();
			}
			
			// Same as this one?
			if (selfptr == __cldx)
				return 1;
			
			// See if our class or any of our super class implemented
			// interfaces matches the target class
			for (ClassInfo xface : mine.interfaceclasses)
			{
				int ifaceptr = xface.selfptr;
				
				// Make sure we are not reading bad memory
				if (ifaceptr == Constants.BAD_MAGIC)
				{
					Assembly.breakpoint();
					throw new VirtualMachineError();
				}
				
				// Is a match?
				if (ifaceptr == __cldx)
					return 1;
			}
		}
		
................................................................................
	 * @param __cldx The class index pointer.
	 * @since 2019/05/26
	 */
	public static final Class<?> jvmLoadClass(int __cldx)
	{
		// Access of invalid class?
		if (__cldx == Constants.BAD_MAGIC)
		{
			Assembly.breakpoint();
			throw new VirtualMachineError();
		}
		
		Assembly.breakpoint();
		throw new todo.TODO();
	}
	
	/**
	 * Loads a string from memory and returns an `intern()` string value.
................................................................................
	public static final String jvmLoadStringNoIntern(int __p)
	{
		// Note
		todo.DEBUG.code('J', 'S', __p);
		
		// Access of invalid object?
		if (__p == Constants.BAD_MAGIC)
		{
			Assembly.breakpoint();
			throw new VirtualMachineError();
		}
		
		// Cannot load from a null string
		if (__p == 0)
		{
			Assembly.breakpoint();
			throw new VirtualMachineError();
		}
		
		// Read length of the raw bytes
		int rawlen = Assembly.memReadJavaShort(__p, 0) & 0xFFFF;
		
		// Load the string data into bytes
		byte[] bytes = new byte[rawlen];
		for (int i = 0, base = __p + 2; i < rawlen; i++)
................................................................................
	 * @param __p The object to enter.
	 * @since 2019/04/26
	 */
	public static final void jvmMonitorEnter(int __p)
	{
		// Access of invalid object?
		if (__p == Constants.BAD_MAGIC)
		{
			Assembly.breakpoint();
			throw new VirtualMachineError();
		}
		
		Assembly.breakpoint();
		throw new todo.TODO();
	}
	
	/**
	 * Exits the monitor for the given object.
................................................................................
	 * @param __p The object to exit.
	 * @since 2019/04/26
	 */
	public static final void jvmMonitorExit(int __p)
	{
		// Access of invalid object?
		if (__p == Constants.BAD_MAGIC)
		{
			Assembly.breakpoint();
			throw new VirtualMachineError();
		}
		
		Assembly.breakpoint();
		throw new todo.TODO();
	}
	
	/**
	 * Allocates a new object.
................................................................................
	 * @return The resulting class pointer.
	 * @since 2019/05/24
	 */
	public static final int jvmNew(int __cl)
	{
		// Access of invalid class?
		if (__cl == Constants.BAD_MAGIC)
		{
			Assembly.breakpoint();
			throw new VirtualMachineError();
		}
		
		// Cannot allocate a null class
		if (__cl == 0)
		{
			Assembly.breakpoint();
			throw new VirtualMachineError();
		}
		
		// Get the class information for the object to allocate
		ClassInfo info = Assembly.pointerToClassInfo(__cl);
		
		// Allocate the memory
		int rv = Allocator.allocate(info.size);
		if (rv == 0)
................................................................................
	 * @since 2019/04/24
	 */
	public static final int jvmNewArray(int __at, int __len)
		throws NegativeArraySizeException, OutOfMemoryError
	{
		// Access of invalid class?
		if (__at == Constants.BAD_MAGIC)
		{
			Assembly.breakpoint();
			throw new VirtualMachineError();
		}
		
		// Do not initialize null class
		if (__at == 0)
		{
			Assembly.breakpoint();
			throw new VirtualMachineError();
		}
		
		// Cannot allocate negative length
		if (__len < 0)
			throw new NegativeArraySizeException();
		
		// Get the class information for the array we want to allocate
		ClassInfo info = Assembly.pointerToClassInfo(__at);