Check-in [7deca59704]

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

Overview
Comment:For the profiler thread, add automatic frame times (no last long parameter); Implement the profiler for SummerCoat.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:7deca5970413bf2c5be059a1c4520eca468114e8
User & Date: stephanie.gawroriski 2019-06-30 18:32:55
Context
2019-06-30
18:34
Make Liberapay image secure. check-in: cb5772e9c5 user: stephanie.gawroriski tags: trunk
18:32
For the profiler thread, add automatic frame times (no last long parameter); Implement the profiler for SummerCoat. check-in: 7deca59704 user: stephanie.gawroriski tags: trunk
13:05
Add base for mini CLDC which are just stubs. check-in: 1a1a617462 user: stephanie.gawroriski tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

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

29
30
31
32
33
34
35


36
37
38
39
40
41
42
..
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
...
419
420
421
422
423
424
425

426
427
428
429
430
431
432
....
1046
1047
1048
1049
1050
1051
1052
1053

1054

1055
1056
1057
1058
































1059
1060
1061
1062
1063
1064
1065
import java.io.OutputStream;
import java.io.PrintStream;
import java.util.LinkedList;
import java.util.List;
import net.multiphasicapps.classfile.InstructionMnemonics;
import net.multiphasicapps.collections.IntegerList;
import net.multiphasicapps.io.HexDumpOutputStream;



/**
 * This represents a native CPU which may run within its own thread to
 * execute code that is running from within the virtual machine.
 *
 * @since 2019/04/21
 */
................................................................................
	
	/** The machine state. */
	protected final MachineState state;
	
	/** The memory to read/write from. */
	protected final WritableMemory memory;
	






	/** Stack frames. */
	private final LinkedList<Frame> _frames =
		new LinkedList<>();
	
	/** System call error states for this CPU. */
	private final int[] _syscallerrors =
		new int[SystemCallIndex.NUM_SYSCALLS];
	
	/**
	 * Initializes the native CPU.
	 *
	 * @param __ms The machine state.
	 * @param __mem The memory space.


	 * @throws NullPointerException On null arguments.
	 * @since 2019/04/21
	 */
	public NativeCPU(MachineState __ms, WritableMemory __mem)

		throws NullPointerException
	{
		if (__ms == null || __mem == null)
			throw new NullPointerException("NARG");
		
		this.state = __ms;
		this.memory = __mem;



	}
	
	/**
	 * Enters the given frame for the given address.
	 *
	 * @param __pc The address of the frame.
	 * @param __args Arguments to the frame
................................................................................
					// Trace it!
					if (ENABLE_DEBUG)
						this.__cpuDebugPrint(nowframe, op, af, args, reglist);
					break;
					
					// Debug exit of method
				case NativeInstructionType.DEBUG_EXIT:

					break;
					
					// Debug point in method.
				case NativeInstructionType.DEBUG_POINT:
					this.__debugPoint(nowframe, args[0], args[1], args[2]);
					break;
				
................................................................................
			imn = memory.memReadInt(pooladdr + (__pmn * 4)),
			imt = memory.memReadInt(pooladdr + (__pmt * 4));
		
		// Store in state
		__f._inclassp = icl;
		__f._inmethodnamep = imn;
		__f._inmethodtypep = imt;
		

		// Load strings

		WritableMemory memory = this.memory;
		__f._inclass = this.__loadUtfString(icl);
		__f._inmethodname = this.__loadUtfString(imn);
		__f._inmethodtype = this.__loadUtfString(imt);
































	}
	
	/**
	 * Sets the debug point in the frame.
	 *
	 * @param __f The frame.
	 * @param __sln The source line.







>
>







 







>
>
>
>
>
>













>
>



|
>







>
>
>







 







>







 








>

>

|
|
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
..
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
116
117
118
119
...
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
....
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
import java.io.OutputStream;
import java.io.PrintStream;
import java.util.LinkedList;
import java.util.List;
import net.multiphasicapps.classfile.InstructionMnemonics;
import net.multiphasicapps.collections.IntegerList;
import net.multiphasicapps.io.HexDumpOutputStream;
import net.multiphasicapps.profiler.ProfilerSnapshot;
import net.multiphasicapps.profiler.ProfiledThread;

/**
 * This represents a native CPU which may run within its own thread to
 * execute code that is running from within the virtual machine.
 *
 * @since 2019/04/21
 */
................................................................................
	
	/** The machine state. */
	protected final MachineState state;
	
	/** The memory to read/write from. */
	protected final WritableMemory memory;
	
	/** The profiler to use. */
	protected final ProfiledThread profiler;
	
	/** Virtual CPU id. */
	protected final int vcpuid;
	
	/** Stack frames. */
	private final LinkedList<Frame> _frames =
		new LinkedList<>();
	
	/** System call error states for this CPU. */
	private final int[] _syscallerrors =
		new int[SystemCallIndex.NUM_SYSCALLS];
	
	/**
	 * Initializes the native CPU.
	 *
	 * @param __ms The machine state.
	 * @param __mem The memory space.
	 * @param __ps The profiler to use.
	 * @param __vcid Virtual CPU id.
	 * @throws NullPointerException On null arguments.
	 * @since 2019/04/21
	 */
	public NativeCPU(MachineState __ms, WritableMemory __mem, int __vcid,
		ProfilerSnapshot __ps)
		throws NullPointerException
	{
		if (__ms == null || __mem == null)
			throw new NullPointerException("NARG");
		
		this.state = __ms;
		this.memory = __mem;
		this.vcpuid = __vcid;
		this.profiler = (__ps == null ? null :
			__ps.measureThread("cpu-" + __vcid));
	}
	
	/**
	 * Enters the given frame for the given address.
	 *
	 * @param __pc The address of the frame.
	 * @param __args Arguments to the frame
................................................................................
					// Trace it!
					if (ENABLE_DEBUG)
						this.__cpuDebugPrint(nowframe, op, af, args, reglist);
					break;
					
					// Debug exit of method
				case NativeInstructionType.DEBUG_EXIT:
					this.__debugExit(nowframe);
					break;
					
					// Debug point in method.
				case NativeInstructionType.DEBUG_POINT:
					this.__debugPoint(nowframe, args[0], args[1], args[2]);
					break;
				
................................................................................
			imn = memory.memReadInt(pooladdr + (__pmn * 4)),
			imt = memory.memReadInt(pooladdr + (__pmt * 4));
		
		// Store in state
		__f._inclassp = icl;
		__f._inmethodnamep = imn;
		__f._inmethodtypep = imt;
		
		
		// Load strings
		String scl, smn, smt;
		WritableMemory memory = this.memory;
		__f._inclass = (scl = this.__loadUtfString(icl));
		__f._inmethodname = (smn = this.__loadUtfString(imn));
		__f._inmethodtype = (smt = this.__loadUtfString(imt));
		
		// Enter it on the profiler
		ProfiledThread profiler = this.profiler;
		if (profiler != null)
			profiler.enterFrame(scl, smn, smt);
	}
	
	/**
	 * Debugs the exit of a frame.
	 *
	 * @param __f The frame to exit.
	 * @throws NullPointerException On null arguments.
	 * @since 2019/06/30
	 */
	private final void __debugExit(Frame __f)
		throws NullPointerException
	{
		if (__f == null)
			throw new NullPointerException("NARG");
		
		// Exit the frame, but if we extra exited then it is very possible
		// that the state can be messed up so do not absolutely destroy the
		// VM stuff
		ProfiledThread profiler = this.profiler;
		if (profiler != null)
			try
			{
				profiler.exitFrame();
			}
			catch (IllegalStateException e)
			{
			}
	}
	
	/**
	 * Sets the debug point in the frame.
	 *
	 * @param __f The frame.
	 * @param __sln The source line.

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

350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
			throw new VMException("AE0h", e);
		}
		
		// Setup non-cpu VM state
		MachineState ms = new MachineState();
		
		// Setup virtual execution CPU
		NativeCPU cpu = new NativeCPU(ms, vmem);
		NativeCPU.Frame iframe = cpu.enterFrame(bootjaroff + bjh.bootstart,
			ramstart, ramsize, rombase, romsize,
			CONFIG_BASE_ADDR, CONFIG_SIZE);
		
		// Seed initial frame registers
		iframe._registers[NativeCode.POOL_REGISTER] =
			ramstart + bjh.bootpool;







|







350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
			throw new VMException("AE0h", e);
		}
		
		// Setup non-cpu VM state
		MachineState ms = new MachineState();
		
		// Setup virtual execution CPU
		NativeCPU cpu = new NativeCPU(ms, vmem, 0, __ps);
		NativeCPU.Frame iframe = cpu.enterFrame(bootjaroff + bjh.bootstart,
			ramstart, ramsize, rombase, romsize,
			CONFIG_BASE_ADDR, CONFIG_SIZE);
		
		// Seed initial frame registers
		iframe._registers[NativeCode.POOL_REGISTER] =
			ramstart + bjh.bootpool;

Changes to runt/libs/tool-profiler/net/multiphasicapps/profiler/ProfiledThread.java.

58
59
60
61
62
63
64















65
66
67
68
69
70
71
...
107
108
109
110
111
112
113










114
115
116
117
118
119
120
...
121
122
123
124
125
126
127














128
129
130
131
132
133
134
		throws NullPointerException
	{
		if (__n == null)
			throw new NullPointerException("NARG");
		
		this.name = __n;
	}















	
	/**
	 * Enters the given frame.
	 *
	 * @param __cl The name of the class.
	 * @param __mn The name of the method.
	 * @param __md The type of the method.
................................................................................
		
		// Indicate that this frame has been entered
		rv.enteredFrame(__ns);
		
		// Using this frame
		return rv;
	}










	
	/**
	 * Exits all frames as needed.
	 *
	 * @param __ns The nanoseconds when exit all has happened.
	 * @since 2018/11/11
	 */
................................................................................
	public void exitAll(long __ns)
	{
		// Empty the frame stack
		Deque<ProfiledFrame> stack = this._stack;
		while (!stack.isEmpty())
			this.exitFrame(__ns);
	}














	
	/**
	 * Exits the frame which at the top of the stack.
	 *
	 * @param __ns The nanoseconds when the frame exited.
	 * @return The exited frame.
	 * @throws IllegalStateException If there is no frame to exit.







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







 







>
>
>
>
>
>
>
>
>
>







 







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







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
...
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
		throws NullPointerException
	{
		if (__n == null)
			throw new NullPointerException("NARG");
		
		this.name = __n;
	}
	
	/**
	 * Enters the given frame, the enter time is the system time.
	 *
	 * @param __cl The name of the class.
	 * @param __mn The name of the method.
	 * @param __md The type of the method.
	 * @throws NullPointerException On null arguments.
	 * @since 2019/06/30
	 */
	public ProfiledFrame enterFrame(String __cl, String __mn, String __md)
		throws NullPointerException
	{
		return this.enterFrame(__cl, __mn, __md, System.nanoTime());
	}
	
	/**
	 * Enters the given frame.
	 *
	 * @param __cl The name of the class.
	 * @param __mn The name of the method.
	 * @param __md The type of the method.
................................................................................
		
		// Indicate that this frame has been entered
		rv.enteredFrame(__ns);
		
		// Using this frame
		return rv;
	}
	
	/**
	 * Exits all frames as needed, the current time is used.
	 *
	 * @since 2019/06/30
	 */
	public void exitAll()
	{
		this.exitAll(System.nanoTime());
	}
	
	/**
	 * Exits all frames as needed.
	 *
	 * @param __ns The nanoseconds when exit all has happened.
	 * @since 2018/11/11
	 */
................................................................................
	public void exitAll(long __ns)
	{
		// Empty the frame stack
		Deque<ProfiledFrame> stack = this._stack;
		while (!stack.isEmpty())
			this.exitFrame(__ns);
	}
	
	/**
	 * Exits the frame which at the top of the stack, the current time is
	 * used.
	 *
	 * @return The exited frame.
	 * @throws IllegalStateException If there is no frame to exit.
	 * @since 2018/11/10
	 */
	public ProfiledFrame exitFrame()
		throws IllegalStateException
	{
		return this.exitFrame(System.nanoTime());
	}
	
	/**
	 * Exits the frame which at the top of the stack.
	 *
	 * @param __ns The nanoseconds when the frame exited.
	 * @return The exited frame.
	 * @throws IllegalStateException If there is no frame to exit.