Check-in [324a3f395e]

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

Overview
Comment:Initialization of execution slices but not printing of them yet.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk | x-date-201911
Files: files | file ages | folders
SHA1: 324a3f395e6289dc9ff6d5097d54f36b46fc4e21
User & Date: stephanie.gawroriski 2019-11-03 11:17:43
Context
2019-11-03
11:42
Printing of base execution slices. check-in: a0f2f0263a user: stephanie.gawroriski tags: trunk
11:17
Initialization of execution slices but not printing of them yet. check-in: 324a3f395e user: stephanie.gawroriski tags: trunk, x-date-201911
2019-10-28
07:02
Backup developer notes. check-in: be8878b1ca user: squirreljme tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

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

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
...
178
179
180
181
182
183
184

185
186
187

188
189
190
191
192
193

194
195
196
197
198
199
200
201
202
203
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
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
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319

320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
// ---------------------------------------------------------------------------
// SquirrelJME is under the GNU General Public License v3+, or later.
// See license.mkd for licensing and copyright information.
// ---------------------------------------------------------------------------

package cc.squirreljme.vm.summercoat;


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 java.io.PrintStream;

/**
 * This represents a single slice of execution.
 *
 * @since 2019/10/27
 */
public final class ExecutionSlice
{














































	/**
	 * Prints the information about this slice.
	 *
	 * @since 2019/10/27
	 */
	public final void print()
	{
................................................................................
		out.println("]");
		*/
	}
	
	/**
	 * Creates an execution slice of the given frame information.
	 *

	 * @param __nf The native frame.
	 * @param __op The operand.
	 * @param __args The arguments.

	 * @param __reglist The register list for method calls.
	 * @return The execution slice.
	 * @throws NullPointerException On null arguments.
	 * @since 2019/10/27
	 */
	public static final ExecutionSlice of(NativeCPU.Frame __nf, int __op,

		int[] __args, int[] __reglist)
		throws NullPointerException
	{
		if (__nf == null || __args == null)
			throw new NullPointerException("NARG");
		
		throw new todo.TODO();
		
		/*
		PrintStream out = System.err;
		
		// Limit class name
		CallTraceElement trace = this.trace(__nf);
		String cname = "" + trace.className();
		int nl;
		if ((nl = cname.length()) > 20)
			cname = cname.substring(nl - 20, nl);
		
		// Print Header (with location info)
		out.printf("***** @%08x %-19.19s/%10.10s | L%-4d/J%-3d %20.20s::%s %n",

			__nf._pc,
			NativeInstruction.mnemonic(__op),
			InstructionMnemonics.toString(trace.byteCodeInstruction()),
			trace.line(),
			trace.byteCodeAddress(),
			cname,
			trace.methodName() + ":" + trace.methodDescriptor());
		
		// Is this an invoke?
		boolean isinvoke = (__op == NativeInstructionType.INVOKE ||
			__op == NativeInstructionType.SYSTEM_CALL);
		
		// Arguments to print, invocations get 1 (pc) + register list
		int naf = (isinvoke ? 1 + __reglist.length:
			__af.length);
		
		// Used to modify some calls
		int encoding = NativeInstruction.encoding(__op);
		
		// Print out arguments to the call
		out.printf("  A:[");
		for (int i = 0, n = naf; i < n; i++)
		{
			int iv = (isinvoke ? (i == 0 ? __args[i] : __reglist[i - 1]) :

				__args[i]);
			
			// Comma
			if (i > 0)
				out.print(", ");
			
			// Can be special?
			boolean canspec = true;
			if (encoding == NativeInstructionType.DEBUG_ENTRY ||
				encoding == NativeInstructionType.DEBUG_POINT ||
				(encoding == NativeInstructionType.IF_ICMP &&
					i == 2) ||
				(encoding == NativeInstructionType.MATH_CONST_INT &&
					i == 1) ||
				(encoding == NativeInstructionType.IFEQ_CONST &&
					i == 1) ||
				(encoding == NativeInstructionType.ATOMIC_INT_INCREMENT &&
					i == 1) ||
				(encoding == NativeInstructionType.
					ATOMIC_INT_DECREMENT_AND_GET && i == 2) ||
				(encoding == NativeInstructionType.MEMORY_OFF_ICONST &&
					i == 2) ||
				(encoding == NativeInstructionType.LOAD_POOL && i == 0))
				canspec = false;
			
			// Is this a special register?
			String spec = null;
			if (canspec)
				switch (iv)
				{
					case NativeCode.ZERO_REGISTER:
						spec = "zero";
						break;
					
					case NativeCode.RETURN_REGISTER:
						spec = "return1";
						break;
					
					case NativeCode.RETURN_REGISTER + 1:
						spec = "return2";
						break;
					
					case NativeCode.EXCEPTION_REGISTER:
						spec = "exception";
						break;
					
					case NativeCode.STATIC_FIELD_REGISTER:
						spec = "sfieldptr";
						break;
					
					case NativeCode.THREAD_REGISTER:
						spec = "thread";
						break;
					
					case NativeCode.POOL_REGISTER:
						spec = "pool";
						break;
					
					case NativeCode.NEXT_POOL_REGISTER:
						spec = "nextpool";
						break;
					
					case NativeCode.ARGUMENT_REGISTER_BASE:
						spec = "a0/this";
						break;
				}
			
			// Print special register
			if (spec != null)
				out.printf("%10.10s", spec);
			else
				out.printf("%10d", iv);
		}
		out.print("] | ");
		
		// And register value
		out.printf("V:[");
		int[] registers = __nf._registers;
		for (int i = 0, n = naf; i < n; i++)
		{
			int iv = (isinvoke ? (i == 0 ? __args[i] : __reglist[i - 1]) :
				__args[i]);

				
			if (i > 0)
				out.print(", ");
			
			// Load register value
			if (iv < 0 || iv >= registers.length)
				out.print("----------");
			else
				out.printf("%+10d", registers[iv]);
		}
		out.println("]");
		*/
	}
}








>













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







 







>



>





|
>
|





<
<
<
<
<
<
<
<
<
<
<
<
<
<
>
|
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
>
|
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
|
>
|
<
<
|
<
<
<
<
<
|
<
<
<
<
<
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
66
67
68
69
70
71
72
73
74
75
76
77
78
...
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





// ---------------------------------------------------------------------------
// SquirrelJME is under the GNU General Public License v3+, or later.
// See license.mkd for licensing and copyright information.
// ---------------------------------------------------------------------------

package cc.squirreljme.vm.summercoat;

import cc.squirreljme.runtime.cldc.debug.CallTraceElement;
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 java.io.PrintStream;

/**
 * This represents a single slice of execution.
 *
 * @since 2019/10/27
 */
public final class ExecutionSlice
{
	/** The tracing information. */
	protected final CallTraceElement trace;
	
	/** The operand executed. */
	protected final int op;
	
	/** Operand arguments. */
	private final int[] _opargs;
	
	/** CPU registers. */
	private final int[] _cpuregs;
	
	/** Method call arguments (optional). */
	private final int[] _callargs;
	
	/**
	 * Creates an execution slice of the given frame information.
	 *
	 * @param __cte Call trace information.
	 * @param __rreg CPU registers stored here.
	 * @param __op The operand.
	 * @param __args The arguments.
	 * @param __argslen Number of arguments available.
	 * @param __reglist The register list for method calls.
	 * @return The execution slice.
	 * @throws NullPointerException On null arguments.
	 * @since 2019/11/03
	 */
	public ExecutionSlice(CallTraceElement __cte, int[] __rreg,
		int __op, int[] __args, int __argslen, int[] __reglist)
		throws NullPointerException
	{
		if (__cte == null || __rreg == null || __args == null)
			throw new NullPointerException("NARG");
		
		this.trace = __cte;
		this._cpuregs = __rreg.clone();
		this.op = __op;
		this._callargs = (__reglist != null ? __reglist.clone() : null);
		
		int[] args = new int[__argslen];
		for (int i = 0; i < __argslen; i++)
			args[i] = __args[i];
		this._opargs = args;
	}
	
	/**
	 * Prints the information about this slice.
	 *
	 * @since 2019/10/27
	 */
	public final void print()
	{
................................................................................
		out.println("]");
		*/
	}
	
	/**
	 * Creates an execution slice of the given frame information.
	 *
	 * @param __cte The call trace information.
	 * @param __nf The native frame.
	 * @param __op The operand.
	 * @param __args The arguments.
	 * @param __argslen Arguments available.
	 * @param __reglist The register list for method calls.
	 * @return The execution slice.
	 * @throws NullPointerException On null arguments.
	 * @since 2019/10/27
	 */
	public static final ExecutionSlice of(CallTraceElement __cte,
		NativeCPU.Frame __nf, int __op, int[] __args, int __argslen,
		int[] __reglist)
		throws NullPointerException
	{
		if (__nf == null || __args == null)
			throw new NullPointerException("NARG");
		














		return new ExecutionSlice(__cte,
			__nf._registers,























			__op,
			__args,
















































































			__argslen,
			__reglist);
	}


}











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

216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
...
419
420
421
422
423
424
425
426

427
428
429
430
431
432
433
			// Spacer
			System.err.println("********************************************");
			
			// Print all the various execution slices
			Deque<ExecutionSlice> execslices = this._execslices;
			System.err.printf("Printing the last %d instructions:%n",
				execslices.size());
			while (execslices.isEmpty())
				execslices.removeFirst().print();
			
			// Spacer
			System.err.println("--------------------------------------------");
			
			// Print the call trace
			CallTraceElement[] calltrace = this.trace();
................................................................................
			if (encoding == NativeInstructionType.DEBUG_ENTRY)
			{
				firstpoint = true;
				pointcounter = 0;
			}
			
			// Get slice for this instruction
			ExecutionSlice el = ExecutionSlice.of(nowframe, op, args, reglist);

			
			// Add to previous instructions, do not exceed slice limits
			if (execslices.size() >= MAX_EXECUTION_SLICES)
				execslices.removeFirst();
			execslices.addLast(el);
			
			// Print CPU debug info







|







 







|
>







216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
...
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
			// Spacer
			System.err.println("********************************************");
			
			// Print all the various execution slices
			Deque<ExecutionSlice> execslices = this._execslices;
			System.err.printf("Printing the last %d instructions:%n",
				execslices.size());
			while (!execslices.isEmpty())
				execslices.removeFirst().print();
			
			// Spacer
			System.err.println("--------------------------------------------");
			
			// Print the call trace
			CallTraceElement[] calltrace = this.trace();
................................................................................
			if (encoding == NativeInstructionType.DEBUG_ENTRY)
			{
				firstpoint = true;
				pointcounter = 0;
			}
			
			// Get slice for this instruction
			ExecutionSlice el = ExecutionSlice.of(this.trace(nowframe),
				nowframe, op, args, af.length, reglist);
			
			// Add to previous instructions, do not exceed slice limits
			if (execslices.size() >= MAX_EXECUTION_SLICES)
				execslices.removeFirst();
			execslices.addLast(el);
			
			// Print CPU debug info