Check-in [8714582c83]

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

Overview
Comment:Add actual VirtualMachine class for SummerCoat which runs it.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:8714582c83798e077323c554f2f0ee6db0edfab8
User & Date: stephanie.gawroriski 2019-06-30 19:37:45
Context
2019-06-30
19:41
Add exitAll() to ProfilerSnapshot without a time. check-in: f90a142aa8 user: stephanie.gawroriski tags: trunk
19:37
Add actual VirtualMachine class for SummerCoat which runs it. check-in: 8714582c83 user: stephanie.gawroriski tags: trunk
18:55
Re-order badges. check-in: dbadc18919 user: stephanie.gawroriski tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

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

361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
		
		// Seed initial frame registers
		iframe._registers[NativeCode.POOL_REGISTER] =
			ramstart + bjh.bootpool;
		iframe._registers[NativeCode.STATIC_FIELD_REGISTER] =
			ramstart + bjh.bootsfieldbase;
		
		// Execute the CPU to boot the machine
		cpu.run();
		
		throw new todo.TODO();
	}
	
	/**
	 * Converts a class path to a string array.
	 *
	 * @param __cp The class path to convert.
	 * @return The resulting string array.







|
|
<
<







361
362
363
364
365
366
367
368
369


370
371
372
373
374
375
376
		
		// Seed initial frame registers
		iframe._registers[NativeCode.POOL_REGISTER] =
			ramstart + bjh.bootpool;
		iframe._registers[NativeCode.STATIC_FIELD_REGISTER] =
			ramstart + bjh.bootsfieldbase;
		
		// Setup virtual machine with initial thread
		return new SummerCoatVirtualMachine(cpu);


	}
	
	/**
	 * Converts a class path to a string array.
	 *
	 * @param __cp The class path to convert.
	 * @return The resulting string array.

Added runt/libs/summercoat-vm/cc/squirreljme/vm/summercoat/SummerCoatVirtualMachine.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
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
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
// -*- Mode: Java; indent-tabs-mode: t; tab-width: 4 -*-
// ---------------------------------------------------------------------------
// Multi-Phasic Applications: SquirrelJME
//     Copyright (C) Stephanie Gawroriski <xer@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.VirtualMachine;
import cc.squirreljme.vm.VMException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

/**
 * This represents a virtual machine within SummerCoat.
 *
 * @since 2019/06/30
 */
public class SummerCoatVirtualMachine
	implements VirtualMachine
{
	/** Threads currently running. */
	private final List<Thread> _threads =
		new ArrayList<>();
	
	/**
	 * Initializes the virtual machine.
	 *
	 * @param __bootcpu The boot CPU.
	 * @throws NullPointerException On null arguments.
	 * @since 2019/06/30
	 */
	public SummerCoatVirtualMachine(NativeCPU __bootcpu)
		throws NullPointerException
	{
		if (__bootcpu == null)
			throw new NullPointerException("NARG");
		
		// Add initial thread
		this._threads.add(new Thread(__bootcpu, "BootCPU"));
	}
	
	/**
	 * {@inheritDoc}
	 * @since 2019/06/30
	 */
	@Override
	public final int runVm()
		throws VMException
	{
		// Start all threads
		List<Thread> threads = this._threads;
		synchronized (threads)
		{
			// Run threads
			for (int i = 0, n = threads.size(); i < n; i++)
				try
				{
					// Start the thread
					threads.get(i).start();
				}
				
				// Ignore, in the event this was called multiple times!
				catch (IllegalThreadStateException e)
				{
				}
		} 
		
		// Wait for all threads to stop
		for (;;)
		{
			// Available threads
			int count = 0;
			
			// Lock!
			synchronized (threads)
			{
				// Get iterator
				Iterator<Thread> it = threads.iterator();
				
				// Ask about all the threads
				while (it.hasNext())
				{
					// Get the thread
					Thread t = it.next();
					
					// If thread is alive, count it
					if (t.isAlive())
						count++;
					
					// Otherwise remove it
					else
						it.remove();
				}
				
				// If there are many threads alive, just wait around to not
				// waste CPU and poll periodically for the thread states
				if (count > 0)
					try
					{
						threads.wait(1000L);
					}
					catch (InterruptedException e)
					{
					}
			}
			
			// Return error for now
			if (count == 0)
			{
				todo.TODO.note("Actual return value!");
				return 1;
			}
		}
	}
}