Check-in [bbfc2a1cb7]

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

Overview
Comment:Move a bunch of the task information into TaskStatus so there are no circular references; Base creation of threads (which are stored via weak reference in task status).
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:bbfc2a1cb7bce01ab4333ac35deabcd30ded400c
User & Date: stephanie.gawroriski 2019-01-10 22:10:51
Context
2019-01-10
22:42
Start the thread after it has been setup. check-in: cea9d9902b user: stephanie.gawroriski tags: trunk
22:10
Move a bunch of the task information into TaskStatus so there are no circular references; Base creation of threads (which are stored via weak reference in task status). check-in: bbfc2a1cb7 user: stephanie.gawroriski tags: trunk
2019-01-07
08:02
Backup developer notes. check-in: b801540475 user: squirreljme tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

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

100
101
102
103
104
105
106
107
108
109
110
111

112


113
114
115
116
117
118
119
120
121
122
123
		for (String s : __args)
			if (s == null)
				throw new NullPointerException("NARG");
		for (Map.Entry<String, String> e : __sprops.entrySet())
			if (e.getKey() == null || e.getValue() == null)
				throw new NullPointerException("NARG");
		
		// Setup class loader for this task
		ClassLoader cl = new ClassLoader(this.runtimeclasscache, suites, __cp);
		
		// Create a new status for this task which contains some global
		// information that is needed

		TaskStatus status = this.statuses.createNew();


		
		// Setup a new base running task, which has no threads yet until the
		// first is created
		RunningTask rv = new RunningTask(status, cl, __sprops, this.profiler);
		
		// Create a new main thread which will be where our execution context
		// will be (since we need to initialize objects)
		RunningThread thr = rv.createThread();
		
		// Setup main thread
		if (true)







<
<
<

|
>
|
>
>



|







100
101
102
103
104
105
106



107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
		for (String s : __args)
			if (s == null)
				throw new NullPointerException("NARG");
		for (Map.Entry<String, String> e : __sprops.entrySet())
			if (e.getKey() == null || e.getValue() == null)
				throw new NullPointerException("NARG");
		



		// Create a new status for this task which contains some global
		// information that is needed, it needs our system properties and the
		// classpath since they both may be accessed
		TaskStatus status = this.statuses.createNew(
			new ClassLoader(this.runtimeclasscache, suites, __cp),
			__sprops, this.profiler);
		
		// Setup a new base running task, which has no threads yet until the
		// first is created
		RunningTask rv = new RunningTask(status);
		
		// Create a new main thread which will be where our execution context
		// will be (since we need to initialize objects)
		RunningThread thr = rv.createThread();
		
		// Setup main thread
		if (true)

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

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






 * @since 2019/01/01
 */
public final class RunningTask
{
	/** The status of this task. */
	protected final TaskStatus status;
	
	/** The class loader. */
	protected final ClassLoader classloader;
	
	/** The profiler information output. */
	protected final ProfilerSnapshot profiler;
	
	/** System properties. */
	private final Map<String, String> _sysprops;
	
	/** Threads which are available for usage. */
	private final Map<Integer, RunningThread> _threads =
		new HashMap<>();
	
	/** The next thread ID. */
	private volatile int _nextthreadid;
	
	/**
	 * Initializes the running task.
	 *
	 * @param __st The task status.
	 * @param __cl The class loader.
	 * @param __sprops System properties.
	 * @param __p Profiler information.
	 * @throws NullPointerException On null arguments.
	 * @since 2019/01/05
	 */
	public RunningTask(TaskStatus __st, ClassLoader __cl,
		Map<String, String> __sprops, ProfilerSnapshot __p)
		throws NullPointerException
	{
		if (__st == null || __cl == null)
			throw new NullPointerException("NARG");
		
		// Defensive copy and check for nulls
		__sprops = (__sprops == null ? new HashMap<String, String>() :
			new HashMap<>(__sprops));
		for (Map.Entry<String, String> e : __sprops.entrySet())
			if (e.getKey() == null || e.getValue() == null)
				throw new NullPointerException("NARG");
		
		// Set
		this.status = __st;








		this.classloader = __cl;
		this.profiler = __p;

		this._sysprops = __sprops;







	}




}
















<
<
<
<
<
<
<
<
<
<
<
<
<













|
<


|


<
<
<
<
<
<
<


>
>
>
>
>
>
>
>
|
<
>
|
>
>
>
>
>
>
>
|
>
>
>
>
|
>
>
|
>
>
>
>
>
>
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
79
80
81
82
83
84
 * @since 2019/01/01
 */
public final class RunningTask
{
	/** The status of this task. */
	protected final TaskStatus status;
	













	/** The next thread ID. */
	private volatile int _nextthreadid;
	
	/**
	 * Initializes the running task.
	 *
	 * @param __st The task status.
	 * @param __cl The class loader.
	 * @param __sprops System properties.
	 * @param __p Profiler information.
	 * @throws NullPointerException On null arguments.
	 * @since 2019/01/05
	 */
	public RunningTask(TaskStatus __st)

		throws NullPointerException
	{
		if (__st == null)
			throw new NullPointerException("NARG");
		







		// Set
		this.status = __st;
	}
	
	/**
	 * Creates a new thread and returns it, the thread will be blank and will
	 * have no state attached to it. It is not started unless it is explictely
	 * started.
	 *
	 * @return The created thread.
	 * @since 2019/01/10

	 */
	public final RunningThread createThread()
	{
		// Lock on self since we need to increment our next ID and add the
		// actual thread
		synchronized (this)
		{
			// Use the next thread ID, whatever that is
			int usetid = this._nextthreadid++;
			
			// Setup new thread using our status since the state information
			// is there instead of in this task instance
			TaskStatus status = this.status;
			RunningThread rv = new RunningThread(usetid, status);
			
			// Register thread with our status
			status.__registerThread(rv);
			
			// The thread being returned will be blank
			return rv;
		}
	}
}

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

8
9
10
11
12
13
14



15
16
17
18
19
20
























21
22
23
24
25
26
27
28
29
30
31
// See license.mkd for licensing and copyright information.
// ---------------------------------------------------------------------------

package cc.squirreljme.vm.summercoat;

/**
 * This represents a thread which is running in the virtual machine.



 *
 * @since 2019/01/05
 */
public final class RunningThread
	implements Runnable
{
























	/**
	 * {@inheritDoc}
	 * @since 2019/01/05
	 */
	@Override
	public void run()
	{
		throw new todo.TODO();
	}
}








>
>
>




|

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











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
// See license.mkd for licensing and copyright information.
// ---------------------------------------------------------------------------

package cc.squirreljme.vm.summercoat;

/**
 * This represents a thread which is running in the virtual machine.
 *
 * This class implements thread itself so it may be interrupted as needed and
 * such.
 *
 * @since 2019/01/05
 */
public final class RunningThread
	extends Thread
{
	/** The ID of this thread. */
	protected final int id;
	
	/** The task status this reports on. */
	protected final TaskStatus status;
	
	/**
	 * Initializes the thread.
	 *
	 * @param __id The thread ID.
	 * @param __s The task status.
	 * @throws NullPointerException On null arguments.
	 * @since 2019/01/10
	 */
	public RunningThread(int __id, TaskStatus __s)
		throws NullPointerException
	{
		if (__s == null)
			throw new NullPointerException("NARG");
		
		this.id = __id;
		this.status = __s;
	}
	
	/**
	 * {@inheritDoc}
	 * @since 2019/01/05
	 */
	@Override
	public void run()
	{
		throw new todo.TODO();
	}
}

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

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
..
45
46
47
48
49
50
51



52
53
54
55

56
57
58
59
60







61
62



63
64



65


















// 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.asm.NativeDisplayEventCallback;






/**
 * This contains the status for a single task and is used to detect when a
 * task is running and if it has ever exited.
 *
 * @since 2019/01/05
 */
................................................................................
public class TaskStatus
{
	/** The monitor or the task statuses, used to signal state changes. */
	protected final Object monitor;
	
	/** The ID of this task. */
	protected final int id;













	
	/** The exit code for this virtual machine. */
	volatile int _exitcode =
		Integer.MIN_VALUE;
	
	/** The state of the task, is initially starting. */
	volatile TaskState _state =
................................................................................
	volatile NativeDisplayEventCallback _eventcallback;
	
	/**
	 * Initializes the task.
	 *
	 * @param __m The monitor to notify when the task changes state.
	 * @param __id The ID of the task.



	 * @throws NullPointerException On null arguments.
	 * @since 2019/01/05
	 */
	public TaskStatus(Object __m, int __id)

		throws NullPointerException
	{
		if (__m == null)
			throw new NullPointerException("NARG");
		







		this.monitor = __m;
		this.id = __id;



	}
}





























>
>
>
>
>







 







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







 







>
>
>



|
>


|


>
>
>
>
>
>
>


>
>
>

|
>
>
>
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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
..
63
64
65
66
67
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
106
107
108
109
110
111
112
113
114
115
116
117
118
// 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.asm.NativeDisplayEventCallback;
import java.lang.ref.Reference;
import java.lang.ref.WeakReference;
import java.util.HashMap;
import java.util.Map;
import net.multiphasicapps.profiler.ProfilerSnapshot;

/**
 * This contains the status for a single task and is used to detect when a
 * task is running and if it has ever exited.
 *
 * @since 2019/01/05
 */
................................................................................
public class TaskStatus
{
	/** The monitor or the task statuses, used to signal state changes. */
	protected final Object monitor;
	
	/** The ID of this task. */
	protected final int id;
	
	/** The class loader. */
	protected final ClassLoader classloader;
	
	/** The profiler information output. */
	protected final ProfilerSnapshot profiler;
	
	/** System properties. */
	private final Map<String, String> _sysprops;
	
	/** Threads which are running. */
	private final Map<Integer, Reference<RunningThread>> _threads =
		new HashMap<>();
	
	/** The exit code for this virtual machine. */
	volatile int _exitcode =
		Integer.MIN_VALUE;
	
	/** The state of the task, is initially starting. */
	volatile TaskState _state =
................................................................................
	volatile NativeDisplayEventCallback _eventcallback;
	
	/**
	 * Initializes the task.
	 *
	 * @param __m The monitor to notify when the task changes state.
	 * @param __id The ID of the task.
	 * @param __cl The class loader used.
	 * @param __sp System properties for this task.
	 * @param __ps Snapshot for the profiler, is optional.
	 * @throws NullPointerException On null arguments.
	 * @since 2019/01/05
	 */
	public TaskStatus(Object __m, int __id, ClassLoader __cl,
		Map<String, String> __sp, ProfilerSnapshot __ps)
		throws NullPointerException
	{
		if (__m == null || __cl == null)
			throw new NullPointerException("NARG");
		
		// Defensive copy and check for nulls
		__sp = (__sp == null ? new HashMap<String, String>() :
			new HashMap<>(__sp));
		for (Map.Entry<String, String> e : __sp.entrySet())
			if (e.getKey() == null || e.getValue() == null)
				throw new NullPointerException("NARG");
		
		this.monitor = __m;
		this.id = __id;
		this.classloader = __cl;
		this.profiler = __ps;
		this._sysprops = __sp;
	}
	
	/**
	 * Registers this thread with this task status, it will have a weak
	 * reference to it and will exist provided it is still running.
	 *
	 * @param __t The thread to register.
	 * @throws NullPointerException On null arguments.
	 * @since 2019/01/10
	 */
	final void __registerThread(RunningThread __t)
		throws NullPointerException
	{
		if (__t == null)
			throw new NullPointerException("NARG");
		
		// Lock on self to add the thread
		synchronized (this)
		{
			this._threads.put(__t.id, new WeakReference<>(__t));
		}
	}
}

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

6
7
8
9
10
11
12


13
14

15
16
17
18
19
20
21
..
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
// ---------------------------------------------------------------------------
// 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 java.util.HashMap;
import java.util.Map;


/**
 * This contains and records the state for multiple tasks which would be
 * running at once, it allows the status to be retrieved for each task
 * regardless of whether it is directly accessible or not.
 *
 * @since 2019/01/05
................................................................................
			}
		}
	}
	
	/**
	 * Creates a status holder for a task giving it a unique ID.
	 *



	 * @return The newly created task with a newly allocated ID.

	 * @since 2019/01/05
	 */
	public final TaskStatus createNew()


	{



		// Lock on self
		Object monitor = this.monitor;
		synchronized (monitor)
		{
			// Setup new task with this ID
			int tid;
			TaskStatus rv = new TaskStatus(monitor, (tid = this._nextid++));

			
			// Need to keep track of this task, so we know when it exits
			this._statuses.put(tid, rv);
			
			// And return the created task
			return rv;
		}
	}
}








>
>


>







 







>
>
>

>


|
>
>

>
>
>






|
>










6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
..
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
120
121
122
123
124
// ---------------------------------------------------------------------------
// 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 java.lang.ref.Reference;
import java.lang.ref.WeakReference;
import java.util.HashMap;
import java.util.Map;
import net.multiphasicapps.profiler.ProfilerSnapshot;

/**
 * This contains and records the state for multiple tasks which would be
 * running at once, it allows the status to be retrieved for each task
 * regardless of whether it is directly accessible or not.
 *
 * @since 2019/01/05
................................................................................
			}
		}
	}
	
	/**
	 * Creates a status holder for a task giving it a unique ID.
	 *
	 * @param __cl The class loader used.
	 * @param __sp System properties used.
	 * @param __ps The profiler snapshot, is optional.
	 * @return The newly created task with a newly allocated ID.
	 * @throws NullPointerException On null arguments.
	 * @since 2019/01/05
	 */
	public final TaskStatus createNew(ClassLoader __cl,
		Map<String, String> __sp, ProfilerSnapshot __ps)
		throws NullPointerException
	{
		if (__cl == null || __sp == null)
			throw new NullPointerException("NARG");
		
		// Lock on self
		Object monitor = this.monitor;
		synchronized (monitor)
		{
			// Setup new task with this ID
			int tid;
			TaskStatus rv = new TaskStatus(monitor, (tid = this._nextid++),
				__cl, __sp, __ps);
			
			// Need to keep track of this task, so we know when it exits
			this._statuses.put(tid, rv);
			
			// And return the created task
			return rv;
		}
	}
}