Check-in [102720fa69]

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

Overview
Comment:Add MethodHandle which is a better and much simpler means to refering to methods for entry and it can have multiple lookup types as well.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:102720fa69e18ab5152f130e5f508a7f947249c2
User & Date: stephanie.gawroriski 2019-01-11 02:21:25
Context
2019-01-11
02:29
Add check for the current thread in another method and call that to make sure calls are not done out of thread. check-in: 915ab69ac6 user: stephanie.gawroriski tags: trunk
02:21
Add MethodHandle which is a better and much simpler means to refering to methods for entry and it can have multiple lookup types as well. check-in: 102720fa69 user: stephanie.gawroriski tags: trunk
01:59
Add base for running methods and such. check-in: af64655e08 user: stephanie.gawroriski tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Added runt/libs/summercoat-vm/cc/squirreljme/vm/summercoat/InstanceMethodHandle.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
// -*- 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 method handle which when called, it will look up the appropriate
 * method to execute for the given object.
 *
 * Lookup will naturally fail if the method is not valid.
 *
 * @since 2019/01/10
 */
public final class InstanceMethodHandle
	implements MethodHandle
{
}

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

6
7
8
9
10
11
12



13
14
15
16
17
18
19

















20
21



















// ---------------------------------------------------------------------------
// 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 class which has been loaded.
 *
 * @since 2019/01/06
 */
public final class LoadedClass
{

















}



























>
>
>







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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
// ---------------------------------------------------------------------------
// 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 net.multiphasicapps.classfile.MethodDescriptor;
import net.multiphasicapps.classfile.MethodName;

/**
 * This represents a class which has been loaded.
 *
 * @since 2019/01/06
 */
public final class LoadedClass
{
	/**
	 * Looks up the given method.
	 *
	 * @param __lut The type of lookup to perform.
	 * @param __static Is the specified method static?
	 * @param __name The name of the method.
	 * @param __desc The method descriptor.
	 * @return The handle to the method.
	 * @throws NullPointerException On null arguments.
	 * @since 2019/01/10
	 */
	public final MethodHandle lookupMethod(MethodLookupType __lut,
		boolean __static, String __name, String __desc)
		throws NullPointerException
	{
		return this.lookupMethod(__lut, __static, new MethodName(__name),
			new MethodDescriptor(__desc));
	}
	
	/**
	 * Looks up the given method.
	 *
	 * @param __lut The type of lookup to perform.
	 * @param __static Is the specified method static?
	 * @param __name The name of the method.
	 * @param __desc The method descriptor.
	 * @return The handle to the method.
	 * @throws NullPointerException On null arguments.
	 * @since 2019/01/10
	 */
	public final MethodHandle lookupMethod(MethodLookupType __lut, 
		boolean __static, MethodName __name, MethodDescriptor __desc)
		throws NullPointerException
	{
		throw new todo.TODO();
	}
}

Added runt/libs/summercoat-vm/cc/squirreljme/vm/summercoat/MethodHandle.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 interface represents a handle to a method, which is used to refer to
 * methods and such.
 *
 * @since 2019/01/10
 */
public interface MethodHandle
{
}

Added runt/libs/summercoat-vm/cc/squirreljme/vm/summercoat/MethodLookupType.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
// -*- 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 the type of lookup to perform when locating a method.
 *
 * @since 2019/01/10
 */
public enum MethodLookupType
{
	/** As instance method, if it is one. */
	INSTANCE,
	
	/** As purely static method. */
	STATIC,
	
	/** End. */
	;
}

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

119
120
121
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
...
154
155
156
157
158
159
160
161

162
163
164
165
166
167
168
169
170
171
172
		// 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();
		



		// Determine the entry method and the entry arguments to use
		Instance vmsm;
		Instance entryarg;
		if (__ismid)
		{
			vmsm = thr.vmStaticMethod(false,
				"javax/microedition/midlet/MIDlet",
				"startApp", "()V");
			entryarg = thr.vmTranslateString(__maincl);
		}
		else
		{
			vmsm = thr.vmStaticMethod(true, __maincl,

				"main", "([Ljava/lang/String;)V");
			
			// Setup array that is the same size as the input arguments
			int n = __args.length;
			ArrayInstance ai = thr.vmNewArray("[Ljava/lang/String;", n);
			
			// Translate string arguments
			for (int i = 0; i < n; i++)
................................................................................
		// accordingly so it knows which method to invoke
		Instance threadobj = thr.vmNewInstance("java/lang/Thread",
			"(Ljava/lang/String;ILcc/squirreljme/runtime/cldc/asm/" +
			"StaticMethod;Ljava/lang/Object;)V", thr.vmTranslateString("Main"),
			IntegerValue.of((__ismid ? 3 : 4)), vmsm, entryarg);
		
		// Enter the __start() method for Thread
		thr.execEnterMethod(false, "java/lang/Thread", "__start", "()V");

		
		// Now that the thread has been initialized it must be started, it
		// will keep running executing the method it starts in until
		// termination occurs
		thr.start();
		
		// Return out created task
		return rv;
	}
}








>
>
>





|
|
|




|
>
|







 







|
>











119
120
121
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
...
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
		// 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();
		
		// Need the thread class to get some methods off it
		LoadedClass thrclass = cl.loadClass("java/lang/Thread");
		
		// Determine the entry method and the entry arguments to use
		Instance vmsm;
		Instance entryarg;
		if (__ismid)
		{
			vmsm = thr.vmStaticMethod(cl.
				loadClass("javax/microedition/midlet/MIDlet").lookupMethod(
				MethodLookupType.INSTANCE, false, "startApp", "()V"));
			entryarg = thr.vmTranslateString(__maincl);
		}
		else
		{
			vmsm = thr.vmStaticMethod(cl.loadClass(__maincl).
				lookupMethod(MethodLookupType.STATIC, true, "main",
				"([Ljava/lang/String;)V"));
			
			// Setup array that is the same size as the input arguments
			int n = __args.length;
			ArrayInstance ai = thr.vmNewArray("[Ljava/lang/String;", n);
			
			// Translate string arguments
			for (int i = 0; i < n; i++)
................................................................................
		// accordingly so it knows which method to invoke
		Instance threadobj = thr.vmNewInstance("java/lang/Thread",
			"(Ljava/lang/String;ILcc/squirreljme/runtime/cldc/asm/" +
			"StaticMethod;Ljava/lang/Object;)V", thr.vmTranslateString("Main"),
			IntegerValue.of((__ismid ? 3 : 4)), vmsm, entryarg);
		
		// Enter the __start() method for Thread
		thr.execEnterMethod(thrclass.lookupMethod(
			MethodLookupType.STATIC, false, "__start", "()V"));
		
		// Now that the thread has been initialized it must be started, it
		// will keep running executing the method it starts in until
		// termination occurs
		thr.start();
		
		// Return out created task
		return rv;
	}
}

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

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
..
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
...
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
			throw new NullPointerException("NARG");
		
		this.id = __id;
		this.status = __s;
	}
	
	/**
	 * Sets up the thread so that the given method is enterred from this
	 * thread.
	 *
	 * @param __static Is this method static?
	 * @param __cl The class to enter.
	 * @param __name The method name.
	 * @param __desc The method type.
	 * @param __args The method arguments.


	 * @throws NullPointerException On null arguments.
	 * @since 2019/01/10
	 */
	public void execEnterMethod(boolean __static, String __cl, String __name,
		String __desc, Value... __args)
		throws NullPointerException
	{





		throw new todo.TODO();
	}
	
	/**
	 * {@inheritDoc}
	 * @since 2019/01/05
	 */
................................................................................
	
	/**
	 * Runs the specified method within the context of this thread and then
	 * returns the value of the execution. Note that if this thread has ever
	 * been started (its {@link run()} method called, then this must only
	 * ever be called by this self.
	 *
	 * @param __static Is this method static?
	 * @param __cl The class to enter.
	 * @param __name The method name.
	 * @param __desc The method type.
	 * @param __args The method arguments.
	 * @return The return value of the method, will be {@code null} on void
	 * types.
	 * @throws IllegalStateException If this thread has been run and the
	 * thread calling this method is not itself.
	 * @throws NullPointerException On null arguments.
	 * @since 2019/01/10
	 */
	public Value runMethod(boolean __static, String __cl, String __name,
		String __desc, Value... __args)
		throws IllegalStateException, NullPointerException
	{



		// {@squirreljme.error AE01 This thread has already been started and
		// as such this method may only be called from within that thread.}
		if (this._didstart && this != Thread.currentThread())
			throw new IllegalStateException("AE01");
		
		throw new todo.TODO();
	}
................................................................................
		
		throw new todo.TODO();
	}
	
	/**
	 * Returns a {@code StaticMethod} to execute the given method.
	 *
	 * @param __static Should a static method be resolved?
	 * @param __cl The class to lookup.
	 * @param __name The method name.
	 * @param __desc The method type.
	 * @return The virtual static method.
	 * @throws NullPointerException On null arguments.
	 * @since 2019/01/10
	 */
	public final Instance vmStaticMethod(boolean __static, String __cl,
		String __name, String __desc)
		throws NullPointerException
	{
		return this.vmStaticMethod(__static,
			this.status.classloader.loadClass(__cl),
			new MethodNameAndType(__name, __desc));
	}
	
	/**
	 * Returns a {@code StaticMethod} to execute the given method.
	 *
	 * @param __static Should a static method be resolved?
	 * @param __cl The class to lookup.
	 * @param __name The method name.
	 * @param __desc The method type.
	 * @return The virtual static method.
	 * @throws NullPointerException On null arguments.
	 * @since 2019/01/10
	 */
	public final Instance vmStaticMethod(boolean __static, LoadedClass __cl,
		String __name, String __desc)
		throws NullPointerException
	{
		return this.vmStaticMethod(__static, __cl,
			new MethodNameAndType(__name, __desc));
	}
	
	/**
	 * Returns a {@code StaticMethod} to execute the given method.
	 *
	 * @param __static Should a static method be resolved?
	 * @param __cl The class to lookup.
	 * @param __nat The method name and type.
	 * @return The virtual static method.
	 * @throws NullPointerException On null arguments.
	 * @since 2019/01/10
	 */
	public final Instance vmStaticMethod(boolean __static, LoadedClass __cl,
		MethodNameAndType __nat)
		throws NullPointerException
	{
		if (__cl == null || __nat == null)
			throw new NullPointerException("NARG");
		
		throw new todo.TODO();
	}
	
	/**
	 * Translates the specified string to an in VM string.
	 *
	 * @param __in The input string.







|
|

|
<
<
<

>
>



|
<
|

>
>
>
>
>







 







|
<
<
<
|







<
|


>
>
>







 







|
<
<
<




|
<


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







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
..
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
...
194
195
196
197
198
199
200
201



202
203
204
205
206

207
208









































209
210
211
212
213
214
215
			throw new NullPointerException("NARG");
		
		this.id = __id;
		this.status = __s;
	}
	
	/**
	 * Sets up the thread so that the given method is entered from this
	 * thread, it is not started.
	 *
	 * @param __mh The method handle.



	 * @param __args The method arguments.
	 * @throws IllegalStateException If the thread has been started and this
	 * is not the current thread.
	 * @throws NullPointerException On null arguments.
	 * @since 2019/01/10
	 */
	public void execEnterMethod(MethodHandle __mh, Value... __args)

		throws IllegalStateException, NullPointerException
	{
		// {@squirreljme.error AE02 This thread has already been started and
		// as such this method may only be called from within that thread.}
		if (this._didstart && this != Thread.currentThread())
			throw new IllegalStateException("AE02");
		
		throw new todo.TODO();
	}
	
	/**
	 * {@inheritDoc}
	 * @since 2019/01/05
	 */
................................................................................
	
	/**
	 * Runs the specified method within the context of this thread and then
	 * returns the value of the execution. Note that if this thread has ever
	 * been started (its {@link run()} method called, then this must only
	 * ever be called by this self.
	 *
	 * @param __mh The method handle.



	 * @param __args The arguments to the call.
	 * @return The return value of the method, will be {@code null} on void
	 * types.
	 * @throws IllegalStateException If this thread has been run and the
	 * thread calling this method is not itself.
	 * @throws NullPointerException On null arguments.
	 * @since 2019/01/10
	 */

	public Value runMethod(MethodHandle __mh, Value... __args)
		throws IllegalStateException, NullPointerException
	{
		if (__mh == null)
			throw new NullPointerException("NARG");
		
		// {@squirreljme.error AE01 This thread has already been started and
		// as such this method may only be called from within that thread.}
		if (this._didstart && this != Thread.currentThread())
			throw new IllegalStateException("AE01");
		
		throw new todo.TODO();
	}
................................................................................
		
		throw new todo.TODO();
	}
	
	/**
	 * Returns a {@code StaticMethod} to execute the given method.
	 *
	 * @param __mh The method handle.



	 * @return The virtual static method.
	 * @throws NullPointerException On null arguments.
	 * @since 2019/01/10
	 */
	public final Instance vmStaticMethod(MethodHandle __mh)

		throws NullPointerException
	{









































		throw new todo.TODO();
	}
	
	/**
	 * Translates the specified string to an in VM string.
	 *
	 * @param __in The input string.

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















































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
// -*- 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 method handle which is bound to a single method and one where the
 * execution uses the exactly specified method, no lookups are performed.
 *
 * @since 2019/01/10
 */
public final class StaticMethodHandle
	implements MethodHandle
{
}