Check-in [fae09851d5]

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

Overview
Comment:Base for creating new tasks, no threads yet; Add base for clas loader; Have ExitAwaiter wait on TaskStatus instead of on an actual task since it would complicate things.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:fae09851d5b4a8049a93f7ec70d7642ab4d34641
User & Date: stephanie.gawroriski 2019-01-05 21:18:22
Context
2019-01-05
21:29
Use a specific monitor object for task status notifications to make it easier to notify when a task changes state for later checking. check-in: d141949d20 user: stephanie.gawroriski tags: trunk
21:18
Base for creating new tasks, no threads yet; Add base for clas loader; Have ExitAwaiter wait on TaskStatus instead of on an actual task since it would complicate things. check-in: fae09851d5 user: stephanie.gawroriski tags: trunk
18:45
Add base for class processor. check-in: 9453b20a7a user: stephanie.gawroriski tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to runt/apis/cldc-compact/java/lang/Thread.java.

741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
					// Start MIDlet, construct then startApp()
				case _START_MIDLET:
					ObjectAccess.invokeStatic(runmethod,
						ObjectAccess.classByName((String)runargument).
						__newInstance());
					break;
					
					// Start main(String) method
				case _START_MAIN:
					ObjectAccess.invokeStatic(runmethod, runargument);
					break;
					
					// Unknown
				default:
					throw new todo.OOPS();







|







741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
					// Start MIDlet, construct then startApp()
				case _START_MIDLET:
					ObjectAccess.invokeStatic(runmethod,
						ObjectAccess.classByName((String)runargument).
						__newInstance());
					break;
					
					// Start main(String[]) method
				case _START_MAIN:
					ObjectAccess.invokeStatic(runmethod, runargument);
					break;
					
					// Unknown
				default:
					throw new todo.OOPS();

Added runt/libs/summercoat-vm/cc/squirreljme/vm/summercoat/ClassLoader.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
// -*- Mode: Java; indent-tabs-mode: t; tab-width: 4 -*-
// ---------------------------------------------------------------------------
// Multi-Phasic Applications: SquirrelJME
//     Copyright (C) Stephanie Gawroriski <xer@multiphasicapps.net>
//     Copyright (C) Multi-Phasic Applications <multiphasicapps.net>
// ---------------------------------------------------------------------------
// 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.vm.VMClassLibrary;
import cc.squirreljme.vm.VMSuiteManager;

/**
 * This is a class loader which manages and can cache multiple classes.
 *
 * @since 2019/01/05
 */
public final class ClassLoader
{
	/** The class cache. */
	protected final RuntimeClassCache runtimeclasscache;
	
	/** The suite manager. */
	protected final VMSuiteManager suites;
	
	/** The classes in the class path. */
	private final VMClassLibrary[] _classpath;
	
	/**
	 * Initializes the class loader.
	 *
	 * @param __rcc The run-time class cache.
	 * @param __sm The suite manager.
	 * @param __cp The classpath.
	 * @throws NullPointerException On null arguments.
	 * @since 2019/01/05
	 */
	public ClassLoader(RuntimeClassCache __rcc, VMSuiteManager __sm,
		VMClassLibrary[] __cp)
		throws NullPointerException
	{
		if (__rcc == null || __sm == null || __cp == null)
			throw new NullPointerException("NARG");
		
		this.runtimeclasscache = __rcc;
		this.suites = __sm;
		this._classpath = __cp.clone();
	}
}

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

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
79
80
81
82
83
84
85
86
87
88
89
90
91
 */
public final class ExitAwaiter
	implements VirtualMachine
{
	/** Object containing all the task statuses, for termination checks. */
	protected final TaskStatuses statuses;
	
	/** The main task to run. */
	protected final RunningTask task;
	
	/**
	 * Initializes the exit awaiter, when the running task ends it will wait
	 * until the root machine has no running tasks.
	 *
	 * @param __ts The statuses for each task, to determine if any are running.
	 * @param __t The task to run.
	 * @throws NullPointerException On null arguments.
	 * @since 2019/01/02
	 */
	public ExitAwaiter(TaskStatuses __ts, RunningTask __t)
		throws NullPointerException
	{
		if (__ts == null || __t == null)
			throw new NullPointerException("NARG");
		
		this.statuses = __ts;
		this.task = __t;
	}
	
	/**
	 * {@inheritDoc}
	 * @since 2019/01/02
	 */
	@Override
	public final int runVm()
		throws VMException
	{
		// A task could run, but also additionally the VM could have some kind
		// of exception where it cannot continue
		int rv = Integer.MIN_VALUE;
		VMException oopsie = null;
		try
		{
			rv = this.task.runVm();
		}
		catch (VMException e)
		{
			oopsie = e;
		}
		
		// Wait for all tasks to complete
		for (TaskStatuses statuses = this.statuses;;)
			try
			{
				if (statuses.awaitFinished(0))
					break;
			}
			catch (InterruptedException e)
			{
				// Do not care if we get interrupted, just try again
			}
		
		// Throw any caught VM exception, but otherwise use the exit code of
		// the main task since that is the one we care about
		if (oopsie != null)
			throw oopsie;
		return rv;
	}
}








|
|






|



|






|










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












|
|
<
<
<



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
 */
public final class ExitAwaiter
	implements VirtualMachine
{
	/** Object containing all the task statuses, for termination checks. */
	protected final TaskStatuses statuses;
	
	/** The main task being run. */
	protected final TaskStatus maintask;
	
	/**
	 * Initializes the exit awaiter, when the running task ends it will wait
	 * until the root machine has no running tasks.
	 *
	 * @param __ts The statuses for each task, to determine if any are running.
	 * @param __t The main task status.
	 * @throws NullPointerException On null arguments.
	 * @since 2019/01/02
	 */
	public ExitAwaiter(TaskStatuses __ts, TaskStatus __t)
		throws NullPointerException
	{
		if (__ts == null || __t == null)
			throw new NullPointerException("NARG");
		
		this.statuses = __ts;
		this.maintask = __t;
	}
	
	/**
	 * {@inheritDoc}
	 * @since 2019/01/02
	 */
	@Override
	public final int runVm()
		throws VMException
	{













		// Wait for all tasks to complete
		for (TaskStatuses statuses = this.statuses;;)
			try
			{
				if (statuses.awaitFinished(0))
					break;
			}
			catch (InterruptedException e)
			{
				// Do not care if we get interrupted, just try again
			}
		
		// Return the exit code for the main task
		return this.maintask._exitcode;



	}
}

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

36
37
38
39
40
41
42




43
44
45
46
47
48
49
..
96
97
98
99
100
101
102



103
104
105
106






107



108
109
110
	/** The base depth of this virtual machine. */
	protected final int baseguestdepth;
	
	/** Statuses for each task. */
	protected final TaskStatuses statuses =
		new TaskStatuses();
	




	/**
	 * Initializes the root machine.
	 *
	 * @param __s The suite manager.
	 * @param __p The profiler snapshot output, this is optional.
	 * @param __gd The guest depth of this VM.
	 * @throws NullPointerException On null arguments, except for {@code __p}.
................................................................................
		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
		TaskStatus status = this.statuses.createNew();
		






		throw new todo.TODO();



	}
}








>
>
>
>







 







>
>
>




>
>
>
>
>
>
|
>
>
>



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
...
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
125
126
	/** The base depth of this virtual machine. */
	protected final int baseguestdepth;
	
	/** Statuses for each task. */
	protected final TaskStatuses statuses =
		new TaskStatuses();
	
	/** Cache of classes. */
	protected final RuntimeClassCache runtimeclasscache =
		new RuntimeClassCache();
	
	/**
	 * Initializes the root machine.
	 *
	 * @param __s The suite manager.
	 * @param __p The profiler snapshot output, this is optional.
	 * @param __gd The guest depth of this VM.
	 * @throws NullPointerException On null arguments, except for {@code __p}.
................................................................................
		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);
		
		// Setup main thread
		if (true)
			throw new todo.TODO();
		
		// Return out created task
		return rv;
	}
}

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

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

package cc.squirreljme.vm.summercoat;

import cc.squirreljme.vm.VirtualMachine;
import cc.squirreljme.vm.VMClassLibrary;
import cc.squirreljme.vm.VMException;
import cc.squirreljme.vm.VMSuiteManager;


import net.multiphasicapps.profiler.ProfilerSnapshot;

/**
 * This represents a task which is running within the virtual machine.
 *
 * @since 2019/01/01
 */
public final class RunningTask
	implements VirtualMachine
{



















	/**
	 * {@inheritDoc}







	 * @since 2019/01/01
	 */
	@Override
	public final int runVm()


		throws VMException
	{
		throw new todo.TODO();















	}
}








>
>

>






<

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

<
>
>
>
>
>
>
>
|

<
<
>
>
|

<
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>



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

package cc.squirreljme.vm.summercoat;

import cc.squirreljme.vm.VirtualMachine;
import cc.squirreljme.vm.VMClassLibrary;
import cc.squirreljme.vm.VMException;
import cc.squirreljme.vm.VMSuiteManager;
import java.util.HashMap;
import java.util.Map;
import net.multiphasicapps.profiler.ProfilerSnapshot;

/**
 * This represents a task which is running within the virtual machine.
 *
 * @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;
	}
}

Added runt/libs/summercoat-vm/cc/squirreljme/vm/summercoat/RunningThread.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
// -*- Mode: Java; indent-tabs-mode: t; tab-width: 4 -*-
// ---------------------------------------------------------------------------
// Multi-Phasic Applications: SquirrelJME
//     Copyright (C) Stephanie Gawroriski <xer@multiphasicapps.net>
//     Copyright (C) Multi-Phasic Applications <multiphasicapps.net>
// ---------------------------------------------------------------------------
// SquirrelJME is under the GNU General Public License v3+, or later.
// 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();
	}
}

Added runt/libs/summercoat-vm/cc/squirreljme/vm/summercoat/RuntimeClassCache.java.













































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
// -*- Mode: Java; indent-tabs-mode: t; tab-width: 4 -*-
// ---------------------------------------------------------------------------
// Multi-Phasic Applications: SquirrelJME
//     Copyright (C) Stephanie Gawroriski <xer@multiphasicapps.net>
//     Copyright (C) Multi-Phasic Applications <multiphasicapps.net>
// ---------------------------------------------------------------------------
// SquirrelJME is under the GNU General Public License v3+, or later.
// See license.mkd for licensing and copyright information.
// ---------------------------------------------------------------------------

package cc.squirreljme.vm.summercoat;

/**
 * This is a cache of classes so that SCRF translation is kept in the run-time
 * rather than being repeated multiple times over and over.
 *
 * @since 2019/01/05
 */
public final class RuntimeClassCache
{
}

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

50
51
52
53
54
55
56
57
58
59
60
		throws IllegalArgumentException, NullPointerException, VMException
	{
		// Setup root machine which has our base suite manager
		RootMachine rm = new RootMachine(__sm, __ps, __gd);
		
		// Now create the starting main task
		return new ExitAwaiter(rm.statuses,
			rm.createTask(__cp, __maincl, __ismid, __sprops, __args));
	}
}








|



50
51
52
53
54
55
56
57
58
59
60
		throws IllegalArgumentException, NullPointerException, VMException
	{
		// Setup root machine which has our base suite manager
		RootMachine rm = new RootMachine(__sm, __ps, __gd);
		
		// Now create the starting main task
		return new ExitAwaiter(rm.statuses,
			rm.createTask(__cp, __maincl, __ismid, __sprops, __args).status);
	}
}

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

18
19
20
21
22
23
24




25
26
27
28
29
30
31
 *
 * @since 2019/01/05
 */
public class TaskStatus
{
	/** The ID of this task. */
	protected final int id;




	
	/** The state of the task, is initially starting. */
	volatile TaskState _state =
		TaskState.STARTING;
	
	/** Requests that the task be stopped/exited. */
	volatile boolean _requestexit;







>
>
>
>







18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
 *
 * @since 2019/01/05
 */
public class TaskStatus
{
	/** 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 =
		TaskState.STARTING;
	
	/** Requests that the task be stopped/exited. */
	volatile boolean _requestexit;