Check-in [cdf4a27303]

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

Overview
Comment:Add InvalidInstructionException; Add todo.DEBUG.code() for a very basic debug note.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:cdf4a27303ed82b9b50f8aab5dd47591a3dd1e5c
User & Date: stephanie.gawroriski 2019-06-13 22:21:07
Context
2019-06-13
22:31
Remove BREAKPOINT/TODO. check-in: 9263683e9f user: stephanie.gawroriski tags: trunk
22:21
Add InvalidInstructionException; Add todo.DEBUG.code() for a very basic debug note. check-in: cdf4a27303 user: stephanie.gawroriski tags: trunk
21:46
Do not count up replaced fields, instead count down. check-in: db1373b5d4 user: stephanie.gawroriski tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

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

105
106
107
108
109
110
111



112
113
114
115
116
117
118
			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();
		



		// Get class info for this type
		ClassInfo pinfo = Assembly.pointerToClassInfo(pcl);
		
		// If this is an array, elements have to be uncounted
		// Instance fields can be skipped for non-object arrays
		if ((pinfo.flags & Constants.CIF_IS_ARRAY) != 0)
		{







>
>
>







105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
			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);
		
		// If this is an array, elements have to be uncounted
		// Instance fields can be skipped for non-object arrays
		if ((pinfo.flags & Constants.CIF_IS_ARRAY) != 0)
		{

Changes to runt/klib/supervisor/todo/DEBUG.java.

24
25
26
27
28
29
30


































31
32
33
34
35
36
37
	 * Not used.
	 *
	 * @since 2019/05/26
	 */
	private DEBUG()
	{
	}


































	
	/**
	 * Prints a debug note.
	 *
	 * @param __fmt The string format, compatible with Java except that it
	 * is very limited in the formats it supports.
	 * @param __args Arguments to the note.







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







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
	 * Not used.
	 *
	 * @since 2019/05/26
	 */
	private DEBUG()
	{
	}
	
	/**
	 * Prints a very basic debug code.
	 *
	 * @param __a First character.
	 * @param __b Second character.
	 * @param __v Value.
	 * @since 2019/06/13
	 */
	public static final void code(char __a, char __b, int __v)
	{
		// Get the pipe descriptor for standard error, ignore if it fails
		int fd = Assembly.sysCallV(SystemCallIndex.PD_OF_STDERR);
		if (SystemCallError.getError(SystemCallIndex.PD_OF_STDERR) != 0)
			return;
		
		// Pipe characters
		DEBUG.__pipe(fd, __a);
		DEBUG.__pipe(fd, __b);
		DEBUG.__pipe(fd, ' ');
		
		// Print digit as hex, this should print all 8 digits
		for (int i = 28; i >= 0; i -= 4)
		{
			// Get upper most hex
			int h = ((__v >>> i) & 0xF);
			
			// Print letter or number?
			DEBUG.__pipe(fd, (char)(h >= 10 ? 'a' + (h - 10) : '0' + h));
		}
		
		// Ending newline
		DEBUG.__pipe(fd, '\n');
	}
	
	/**
	 * Prints a debug note.
	 *
	 * @param __fmt The string format, compatible with Java except that it
	 * is very limited in the formats it supports.
	 * @param __args Arguments to the note.

Changes to runt/libs/summercoat-vm/cc/squirreljme/vm/summercoat/NativeCPU.java.

11
12
13
14
15
16
17

18
19
20
21
22
23
24
...
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178

import cc.squirreljme.jvm.Constants;
import cc.squirreljme.jvm.SystemCallError;
import cc.squirreljme.jvm.SystemCallIndex;
import cc.squirreljme.runtime.cldc.debug.CallTraceElement;
import cc.squirreljme.vm.VMException;
import dev.shadowtail.classfile.nncc.ArgumentFormat;

import dev.shadowtail.classfile.nncc.NativeCode;
import dev.shadowtail.classfile.nncc.NativeInstruction;
import dev.shadowtail.classfile.nncc.NativeInstructionType;
import dev.shadowtail.classfile.xlate.CompareType;
import dev.shadowtail.classfile.xlate.DataType;
import dev.shadowtail.classfile.xlate.MathType;
import dev.shadowtail.classfile.xlate.StackJavaType;
................................................................................
	{
		try
		{
			this.runWithoutCatch(0);
		}
		
		// Failed
		catch (VMException e)
		{
			// Print the call trace
			CallTraceElement[] calltrace = this.trace();
			System.err.println("Call trace:");
			for (CallTraceElement l : calltrace)
				System.err.printf("    %s%n", l);
			System.err.println();







>







 







|







11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
...
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179

import cc.squirreljme.jvm.Constants;
import cc.squirreljme.jvm.SystemCallError;
import cc.squirreljme.jvm.SystemCallIndex;
import cc.squirreljme.runtime.cldc.debug.CallTraceElement;
import cc.squirreljme.vm.VMException;
import dev.shadowtail.classfile.nncc.ArgumentFormat;
import dev.shadowtail.classfile.nncc.InvalidInstructionException;
import dev.shadowtail.classfile.nncc.NativeCode;
import dev.shadowtail.classfile.nncc.NativeInstruction;
import dev.shadowtail.classfile.nncc.NativeInstructionType;
import dev.shadowtail.classfile.xlate.CompareType;
import dev.shadowtail.classfile.xlate.DataType;
import dev.shadowtail.classfile.xlate.MathType;
import dev.shadowtail.classfile.xlate.StackJavaType;
................................................................................
	{
		try
		{
			this.runWithoutCatch(0);
		}
		
		// Failed
		catch (VMException|InvalidInstructionException e)
		{
			// Print the call trace
			CallTraceElement[] calltrace = this.trace();
			System.err.println("Call trace:");
			for (CallTraceElement l : calltrace)
				System.err.printf("    %s%n", l);
			System.err.println();

Added runt/libs/tool-classfile/dev/shadowtail/classfile/nncc/InvalidInstructionException.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
64
65
// -*- 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 dev.shadowtail.classfile.nncc;

import net.multiphasicapps.classfile.InvalidClassFormatException;

/**
 * This is thrown when an instruction is not valid.
 *
 * @since 2019/06/13
 */
public class InvalidInstructionException
	extends InvalidClassFormatException
{
	/**
	 * Initialize the exception with no message or cause.
	 *
	 * @since 2019/06/13
	 */
	public InvalidInstructionException()
	{
	}
	
	/**
	 * Initialize the exception with a message and no cause.
	 *
	 * @param __m The message.
	 * @since 2019/06/13
	 */
	public InvalidInstructionException(String __m)
	{
		super(__m);
	}
	
	/**
	 * Initialize the exception with a message and cause.
	 *
	 * @param __m The message.
	 * @param __c The cause.
	 * @since 2019/06/13
	 */
	public InvalidInstructionException(String __m, Throwable __c)
	{
		super(__m, __c);
	}
	
	/**
	 * Initialize the exception with no message and with a cause.
	 *
	 * @param __c The cause.
	 * @since 2019/06/13
	 */
	public InvalidInstructionException(Throwable __c)
	{
		super(__c);
	}
}

Changes to runt/libs/tool-classfile/dev/shadowtail/classfile/nncc/NativeInstruction.java.

275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
...
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
...
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
	}
	
	/**
	 * Returns the argument count of the operation.
	 *
	 * @param __op The operation to get the argument count of.
	 * @return The number of used arguments.
	 * @throws IllegalArgumentException If the encoding is not known.
	 * @since 2019/03/27
	 */
	public static final int argumentCount(int __op)
		throws IllegalArgumentException
	{
		// Depends on the encoding
		switch (NativeInstruction.encoding(__op))
		{
			case NativeInstructionType.BREAKPOINT:
			case NativeInstructionType.DEBUG_EXIT:
			case NativeInstructionType.RETURN:
................................................................................
			case NativeInstructionType.MEMORY_OFF_ICONST:
			case NativeInstructionType.MEMORY_OFF_ICONST_JAVA:
				return 3;
				
				// {@squirreljme.error JC2r Unknown instruction argument
				// count.}
			default:
				throw new IllegalArgumentException("JC2r " + __op);
		}
	}
	
	
	/**
	 * Returns the argument format for the instruction.
	 *
................................................................................
			case NativeInstructionType.INVOKE:
				return ArgumentFormat.of(
					ArgumentFormat.VUREG,
					ArgumentFormat.REGLIST);
		}
		
		// {@squirreljme.error JC3t Invalid operation. (The operation)}
		throw new IllegalArgumentException("JC3t " +
			NativeInstruction.mnemonic(__op));
	}
	
	/**
	 * Returns the encoding of the given instruction.
	 *
	 * @param __op The operation to get the encoding of.







|



|







 







|







 







|







275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
...
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
...
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
	}
	
	/**
	 * Returns the argument count of the operation.
	 *
	 * @param __op The operation to get the argument count of.
	 * @return The number of used arguments.
	 * @throws InvalidInstructionException If the encoding is not known.
	 * @since 2019/03/27
	 */
	public static final int argumentCount(int __op)
		throws InvalidInstructionException
	{
		// Depends on the encoding
		switch (NativeInstruction.encoding(__op))
		{
			case NativeInstructionType.BREAKPOINT:
			case NativeInstructionType.DEBUG_EXIT:
			case NativeInstructionType.RETURN:
................................................................................
			case NativeInstructionType.MEMORY_OFF_ICONST:
			case NativeInstructionType.MEMORY_OFF_ICONST_JAVA:
				return 3;
				
				// {@squirreljme.error JC2r Unknown instruction argument
				// count.}
			default:
				throw new InvalidInstructionException("JC2r " + __op);
		}
	}
	
	
	/**
	 * Returns the argument format for the instruction.
	 *
................................................................................
			case NativeInstructionType.INVOKE:
				return ArgumentFormat.of(
					ArgumentFormat.VUREG,
					ArgumentFormat.REGLIST);
		}
		
		// {@squirreljme.error JC3t Invalid operation. (The operation)}
		throw new InvalidInstructionException("JC3t " +
			NativeInstruction.mnemonic(__op));
	}
	
	/**
	 * Returns the encoding of the given instruction.
	 *
	 * @param __op The operation to get the encoding of.