Check-in [d0961b4719]

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

Overview
Comment:Initialize and setting of thread contexts.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | wip-springcoat-bringup
Files: files | file ages | folders
SHA1: d0961b471944d62eaf6a9de45f46281316f2a433
User & Date: stephanie.gawroriski 2020-05-12 13:48:09
Context
2020-05-12
15:54
Commit the context storage in SpringCoat. check-in: b9a5337de4 user: stephanie.gawroriski tags: wip-springcoat-bringup
13:48
Initialize and setting of thread contexts. check-in: d0961b4719 user: stephanie.gawroriski tags: wip-springcoat-bringup
12:38
Implement CHECK_FOR_COMPATIBILITY system call. check-in: 59b3122181 user: stephanie.gawroriski tags: wip-springcoat-bringup
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to emulators/springcoat-vm/src/main/java/cc/squirreljme/vm/springcoat/HardwareThreadManager.java.

10
11
12
13
14
15
16

17
18
19
20
21
22
23
...
126
127
128
129
130
131
132
































133
134
135
136
137
138
139
package cc.squirreljme.vm.springcoat;

import cc.squirreljme.emulator.profiler.ProfilerSnapshot;
import cc.squirreljme.jvm.HardwareThreadControl;
import cc.squirreljme.jvm.SystemCallError;
import cc.squirreljme.jvm.SystemCallException;
import cc.squirreljme.jvm.SystemCallIndex;

import java.util.HashMap;
import java.util.Map;
import java.util.NoSuchElementException;

/**
 * This class manages hardware threads which run within the virtual machine.
 *
................................................................................
			throw new NullPointerException("NARG");
		
		switch (__ctrl)
		{
				// Create hardware thread
			case HardwareThreadControl.CONTROL_CREATE_THREAD:
				return this.createThread().id;
































				
				// Set thread task ID
			case HardwareThreadControl.CONTROL_THREAD_SET_TASKID:
				try
				{
					this.getThread(__a).setTaskId(__b);
					return 0;







>







 







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







10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
...
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
package cc.squirreljme.vm.springcoat;

import cc.squirreljme.emulator.profiler.ProfilerSnapshot;
import cc.squirreljme.jvm.HardwareThreadControl;
import cc.squirreljme.jvm.SystemCallError;
import cc.squirreljme.jvm.SystemCallException;
import cc.squirreljme.jvm.SystemCallIndex;
import cc.squirreljme.runtime.cldc.debug.Debugging;
import java.util.HashMap;
import java.util.Map;
import java.util.NoSuchElementException;

/**
 * This class manages hardware threads which run within the virtual machine.
 *
................................................................................
			throw new NullPointerException("NARG");
		
		switch (__ctrl)
		{
				// Create hardware thread
			case HardwareThreadControl.CONTROL_CREATE_THREAD:
				return this.createThread().id;
				
				// Initialize a new context for the given task
			case HardwareThreadControl.CONTROL_INITIALIZE_CONTEXT:
				try
				{
					this.getThread(__a).initializeContext();
					return 0;
				}
				catch (IllegalStateException e)
				{
					throw new SystemCallException(SystemCallIndex.HW_THREAD,
						SystemCallError.THREAD_HAS_CONTEXT, e);
				}
				
				// Set thread context
			case HardwareThreadControl.CONTROL_SET_CONTEXT:
				try
				{
					this.getThread(__a).setContext(
						this.getThread(__b).context());
					return 0;
				}
				catch (NoSuchElementException e)
				{
					throw new SystemCallException(SystemCallIndex.HW_THREAD,
						SystemCallError.NO_SUCH_THREAD, e);
				}
				catch (IllegalStateException e)
				{
					throw new SystemCallException(SystemCallIndex.HW_THREAD,
						SystemCallError.THREAD_HAS_CONTEXT, e);
				}
				
				// Set thread task ID
			case HardwareThreadControl.CONTROL_THREAD_SET_TASKID:
				try
				{
					this.getThread(__a).setTaskId(__b);
					return 0;

Changes to emulators/springcoat-vm/src/main/java/cc/squirreljme/vm/springcoat/SpringThread.java.

48
49
50
51
52
53
54



55
56
57
58
59
60
61
..
86
87
88
89
90
91
92





















93
94
95
96
97
98
99
...
270
271
272
273
274
275
276



















277
278
279
280
281
282
283
...
388
389
390
391
392
393
394























395
396
397
398
399
400
401
	
	/** The stack frames. */
	private final List<SpringThread.Frame> _frames =
		new ArrayList<>();
	
	/** The task ID of this thread. */
	private int _taskId;



		
	/** String representation. */
	private Reference<String> _string;
	
	/** Ran at least one frame (was started)? */
	private volatile boolean _hadoneframe;
	
................................................................................
		if (__n == null)
			throw new NullPointerException("NARG");
		
		this.id = __id;
		this.name = __n;
		this.profiler = __profiler;
	}





















	
	/**
	 * Returns the current frame of execution or {@code null} if there is none.
	 *
	 * @return The current frame of execution or {@code null} if there is none.
	 * @since 2018/09/03
	 */
................................................................................
		List<SpringThread.Frame> frames = this._frames;
		synchronized (frames)
		{
			return frames.<SpringThread.Frame>toArray(
				new SpringThread.Frame[frames.size()]);
		}
	}



















	
	/**
	 * Is exiting the virtual machine okay?
	 *
	 * @return If it is okay to exit.
	 * @since 2018/11/17
	 */
................................................................................
					pc,
					inmethod.byteCode().getByAddress(pc).mnemonic(),
					inmethod.inFile(),
					inmethod.byteCode().lineOfAddress(pc));
			}
		}
	}























	
	/**
	 * Sets the task ID for this thread.
	 *
	 * @param __id The ID to set.
	 * @since 2020/05/09
	 */







>
>
>







 







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







 







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







 







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







48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
..
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
120
121
122
123
...
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
...
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
	
	/** The stack frames. */
	private final List<SpringThread.Frame> _frames =
		new ArrayList<>();
	
	/** The task ID of this thread. */
	private int _taskId;
	
	/** The context of this thread. */
	private ThreadContext _context;
		
	/** String representation. */
	private Reference<String> _string;
	
	/** Ran at least one frame (was started)? */
	private volatile boolean _hadoneframe;
	
................................................................................
		if (__n == null)
			throw new NullPointerException("NARG");
		
		this.id = __id;
		this.name = __n;
		this.profiler = __profiler;
	}
	
	/**
	 * Returns the thread's context.
	 *
	 * @return The thread's context.
	 * @throws IllegalStateException If this thread has no context
	 * @since 2020/05/12
	 */
	public final ThreadContext context()
		throws IllegalStateException
	{
		ThreadContext rv;
		synchronized (this)
		{
			rv = this._context;
		}
		
		if (rv == null)
			throw new IllegalStateException("Thread has no context.");
		return rv;
	}
	
	/**
	 * Returns the current frame of execution or {@code null} if there is none.
	 *
	 * @return The current frame of execution or {@code null} if there is none.
	 * @since 2018/09/03
	 */
................................................................................
		List<SpringThread.Frame> frames = this._frames;
		synchronized (frames)
		{
			return frames.<SpringThread.Frame>toArray(
				new SpringThread.Frame[frames.size()]);
		}
	}
	
	/**
	 * Initializes the thread with a new context.
	 *
	 * @return The newly created context.
	 * @throws IllegalStateException If the thread already has a context.
	 * @since 2020/05/12
	 */
	public final ThreadContext initializeContext()
		throws IllegalStateException
	{
		// Setup new context
		ThreadContext rv = new ThreadContext();
		
		// Try setting it
		this.setContext(rv);
		
		return rv;
	}
	
	/**
	 * Is exiting the virtual machine okay?
	 *
	 * @return If it is okay to exit.
	 * @since 2018/11/17
	 */
................................................................................
					pc,
					inmethod.byteCode().getByAddress(pc).mnemonic(),
					inmethod.inFile(),
					inmethod.byteCode().lineOfAddress(pc));
			}
		}
	}
	
	/**
	 * Sets the context for a given thread.
	 *
	 * @param __context The context to set.
	 * @throws IllegalStateException If this thread already has a context.
	 * @throws NullPointerException On null arguments.
	 * @since 2020/05/12
	 */
	public final void setContext(ThreadContext __context)
		throws IllegalStateException, NullPointerException
	{
		if (__context == null)
			throw new NullPointerException("NARG");
		
		synchronized (this)
		{
			if (this._context != null)
				throw new IllegalStateException("Thread has a context.");
			
			this._context = __context;
		}
	}
	
	/**
	 * Sets the task ID for this thread.
	 *
	 * @param __id The ID to set.
	 * @since 2020/05/09
	 */

Changes to modules/cldc-compact/src/main/java/cc/squirreljme/jvm/SystemCallError.java.

64
65
66
67
68
69
70




71
72
73
74
75
76
77
...
146
147
148
149
150
151
152






153
154
155
156
157
158
159
160
	public static final byte NO_SUCH_CLASS =
		-11;
	
	/** No such thread exists. */
	public static final byte NO_SUCH_THREAD =
		-12;
	




	/**
	 * Not used.
	 *
	 * @since 2019/05/23
	 */
	private SystemCallError()
	{
................................................................................
				return "EndOfFile";
				
			case SystemCallError.IPC_ERROR:
				return "IPCError";
			
			case SystemCallError.NO_SUCH_CLASS:
				return "NoSuchClass";






			
				// Some Other ID?
			default:
				return "ERROR" + __err;
		}
	}
}








>
>
>
>







 







>
>
>
>
>
>








64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
...
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
	public static final byte NO_SUCH_CLASS =
		-11;
	
	/** No such thread exists. */
	public static final byte NO_SUCH_THREAD =
		-12;
	
	/** Thread already has a context. */
	public static final byte THREAD_HAS_CONTEXT =
		-13;
	
	/**
	 * Not used.
	 *
	 * @since 2019/05/23
	 */
	private SystemCallError()
	{
................................................................................
				return "EndOfFile";
				
			case SystemCallError.IPC_ERROR:
				return "IPCError";
			
			case SystemCallError.NO_SUCH_CLASS:
				return "NoSuchClass";
				
			case SystemCallError.NO_SUCH_THREAD:
				return "NoSuchThread";
			
			case SystemCallError.THREAD_HAS_CONTEXT:
				return "ThreadHasContext";
			
				// Some Other ID?
			default:
				return "ERROR" + __err;
		}
	}
}