Check-in [61e90ad12e]

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

Overview
Comment:Move ObjectAccess.arrayLength() to Assembly.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:61e90ad12eee4b71ba307dffc9fd9a7a539307bd
User & Date: stephanie.gawroriski 2019-05-24 17:09:26
Context
2019-05-24
17:30
Add conversion for system calls. check-in: a11d27d936 user: stephanie.gawroriski tags: trunk
17:09
Move ObjectAccess.arrayLength() to Assembly. check-in: 61e90ad12e user: stephanie.gawroriski tags: trunk
14:39
Remove Memory UTF sequence from the fixed class IDs. check-in: cfbc792882 user: stephanie.gawroriski tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to bldt/javase/libs/javase-runtime/cc/squirreljme/runtime/cldc/asm/ObjectAccess.java.

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
	 */
	@Api(ApiLevel.LEVEL_SQUIRRELJME_0_2_0_20181225)
	public static final Object allocateObject(String __cl)
	{
		return null;
	}
	
	/**
	 * Returns the length of the given array.
	 *
	 * @param __a The array to get the length of.
	 * @return The length of the array or {@code -1} if it is not an
	 * array.
	 * @since 2018/09/25
	 */
	@Api(ApiLevel.LEVEL_SQUIRRELJME_0_2_0_20181225)
	public static final int arrayLength(Object __a)
	{
		return Array.getLength(__a);
	}
	
	/**
	 * Creates a new array of the given type, this is the actual array and
	 * not the component.
	 *
	 * @param __t The array type, not the component type.
	 * @param __l The array length.
	 * @return An array allocated to the given length.







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







55
56
57
58
59
60
61














62
63
64
65
66
67
68
	 */
	@Api(ApiLevel.LEVEL_SQUIRRELJME_0_2_0_20181225)
	public static final Object allocateObject(String __cl)
	{
		return null;
	}
	














	/**
	 * Creates a new array of the given type, this is the actual array and
	 * not the component.
	 *
	 * @param __t The array type, not the component type.
	 * @param __l The array length.
	 * @return An array allocated to the given length.

Changes to bldt/javase/libs/javase-runtime/cc/squirreljme/runtime/cldc/vki/Assembly.java.

6
7
8
9
10
11
12

13
14
15
16
17
18
19
..
32
33
34
35
36
37
38












39
40
41
42
43
44
45
// SquirrelJME is under the GNU General Public License v3+, or later.
// See license.mkd for licensing and copyright information.
// ---------------------------------------------------------------------------

package cc.squirreljme.runtime.cldc.vki;

import cc.squirreljme.runtime.cldc.lang.ApiLevel;


/**
 * This class is used special by the compiler to transform all the various
 * operations into regular instructions rather than method calls.
 *
 * The compiler will take all of the method arguments and instead use their
 * inputs and outputs from the values of registers instead. However due to
................................................................................
	 * Not used.
	 *
	 * @since 2019/04/20
	 */
	private Assembly()
	{
	}












	
	/**
	 * Trigger breakpoint within the virtual machine.
	 *
	 * @since 2019/04/21
	 */
	public static final void breakpoint()







>







 







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







6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
..
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
// SquirrelJME is under the GNU General Public License v3+, or later.
// See license.mkd for licensing and copyright information.
// ---------------------------------------------------------------------------

package cc.squirreljme.runtime.cldc.vki;

import cc.squirreljme.runtime.cldc.lang.ApiLevel;
import java.lang.reflect.Array;

/**
 * This class is used special by the compiler to transform all the various
 * operations into regular instructions rather than method calls.
 *
 * The compiler will take all of the method arguments and instead use their
 * inputs and outputs from the values of registers instead. However due to
................................................................................
	 * Not used.
	 *
	 * @since 2019/04/20
	 */
	private Assembly()
	{
	}
	
	/**
	 * Returns the array length of the given object.
	 *
	 * @param __o The object to get the length of.
	 * @return The length of the array.
	 * @since 2019/05/24
	 */
	public static final int arrayLength(Object __o)
	{
		return Array.getLength(__o);
	}
	
	/**
	 * Trigger breakpoint within the virtual machine.
	 *
	 * @since 2019/04/21
	 */
	public static final void breakpoint()

Changes to runt/apis/cldc-compact/cc/squirreljme/runtime/cldc/asm/ObjectAccess.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
	 * @return An object for the class, it is not initialized with a
	 * constructor. Returns {@code null} if no more memory is available.
	 * @since 2018/12/04
	 */
	@Api(ApiLevel.LEVEL_SQUIRRELJME_0_2_0_20181225)
	public static final native Object allocateObject(String __cl);
	
	/**
	 * Returns the length of the given array.
	 *
	 * @param __a The array to get the length of.
	 * @return The length of the array or {@code -1} if it is not an
	 * array.
	 * @since 2018/09/25
	 */
	@Api(ApiLevel.LEVEL_SQUIRRELJME_0_2_0_20181225)
	public static final native int arrayLength(Object __a);
	
	/**
	 * Creates a new array of the given type, this is the actual array and
	 * not the component.
	 *
	 * @param __t The array type, not the component type.
	 * @param __l The array length.
	 * @return An array allocated to the given length.







<
<
<
<
<
<
<
<
<
<
<







51
52
53
54
55
56
57











58
59
60
61
62
63
64
	 * @return An object for the class, it is not initialized with a
	 * constructor. Returns {@code null} if no more memory is available.
	 * @since 2018/12/04
	 */
	@Api(ApiLevel.LEVEL_SQUIRRELJME_0_2_0_20181225)
	public static final native Object allocateObject(String __cl);
	











	/**
	 * Creates a new array of the given type, this is the actual array and
	 * not the component.
	 *
	 * @param __t The array type, not the component type.
	 * @param __l The array length.
	 * @return An array allocated to the given length.

Changes to runt/apis/cldc-compact/cc/squirreljme/runtime/cldc/vki/Assembly.java.

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
..
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
...
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
	 *
	 * @since 2019/04/20
	 */
	private Assembly()
	{
	}
	









	/**
	 * Trigger breakpoint within the virtual machine.
	 *
	 * @since 2019/04/21
	 */
	public static native void breakpoint();
	
................................................................................
	/**
	 * Double to raw long bits.
	 *
	 * @param __d The input double.
	 * @return The raw long bits.
	 * @since 2018/11/03
	 */
	public static final native long doubleToRawLongBits(double __d);
	
	/**
	 * Performs explicit exception handling.
	 *
	 * @since 2019/04/28
	 */
	public static native void exceptionHandle();
................................................................................
	/**
	 * Float to raw int bits.
	 *
	 * @param __d The input float.
	 * @return The raw int bits.
	 * @since 2018/11/04
	 */
	public static final native int floatToRawIntBits(float __f);
	
	/**
	 * Integer bits to float.
	 *
	 * @param __b The input bits.
	 * @return The resulting float.
	 * @since 2018/11/04
	 */
	public static final native float intBitsToFloat(int __b);
	
	/**
	 * Invoke method at pointer.
	 *
	 * @param __addr The address to invoke.
	 * @since 2019/04/28
	 */
................................................................................
	/**
	 * Long bits to double.
	 *
	 * @param __b The input bits.
	 * @return The resulting double.
	 * @since 2018/11/03
	 */
	public static final native double longBitsToDouble(long __b);
	
	/**
	 * Reads byte from address.
	 *
	 * @param __p The pointer.
	 * @param __o The offset.
	 * @return The result of the read.







>
>
>
>
>
>
>
>
>







 







|







 







|








|







 







|







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
..
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
...
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
	 *
	 * @since 2019/04/20
	 */
	private Assembly()
	{
	}
	
	/**
	 * Returns the array length of the given object.
	 *
	 * @param __o The object to get the length of.
	 * @return The length of the array.
	 * @since 2019/05/24
	 */
	public static native int arrayLength(Object __o);
	
	/**
	 * Trigger breakpoint within the virtual machine.
	 *
	 * @since 2019/04/21
	 */
	public static native void breakpoint();
	
................................................................................
	/**
	 * Double to raw long bits.
	 *
	 * @param __d The input double.
	 * @return The raw long bits.
	 * @since 2018/11/03
	 */
	public static native long doubleToRawLongBits(double __d);
	
	/**
	 * Performs explicit exception handling.
	 *
	 * @since 2019/04/28
	 */
	public static native void exceptionHandle();
................................................................................
	/**
	 * Float to raw int bits.
	 *
	 * @param __d The input float.
	 * @return The raw int bits.
	 * @since 2018/11/04
	 */
	public static native int floatToRawIntBits(float __f);
	
	/**
	 * Integer bits to float.
	 *
	 * @param __b The input bits.
	 * @return The resulting float.
	 * @since 2018/11/04
	 */
	public static native float intBitsToFloat(int __b);
	
	/**
	 * Invoke method at pointer.
	 *
	 * @param __addr The address to invoke.
	 * @since 2019/04/28
	 */
................................................................................
	/**
	 * Long bits to double.
	 *
	 * @param __b The input bits.
	 * @return The resulting double.
	 * @since 2018/11/03
	 */
	public static native double longBitsToDouble(long __b);
	
	/**
	 * Reads byte from address.
	 *
	 * @param __p The pointer.
	 * @param __o The offset.
	 * @return The result of the read.

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

8
9
10
11
12
13
14

15
16
17
18
19
20
21
..
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
// See license.mkd for licensing and copyright information.
// ---------------------------------------------------------------------------

package java.lang;

import cc.squirreljme.runtime.cldc.annotation.ImplementationNote;
import cc.squirreljme.runtime.cldc.asm.ObjectAccess;


/**
 * This class is the root of all class trees in Java.
 *
 * @since 2016/02/08
 */
@ImplementationNote("The Java compiler does not allow any final fields to " +
................................................................................
		throws CloneNotSupportedException
	{
		// If this is an array copy elements around
		Class<?> cl = this.getClass();
		if (cl.isArray())
		{
			// Need length of this array to recreate!
			int len = ObjectAccess.arrayLength(this);
			
			// Allocate new array
			Object dest = ObjectAccess.arrayNew(cl, len);
			
			// Copy everything over
			System.arraycopy(this, 0, dest, 0, len);
			







>







 







|







8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
..
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
// See license.mkd for licensing and copyright information.
// ---------------------------------------------------------------------------

package java.lang;

import cc.squirreljme.runtime.cldc.annotation.ImplementationNote;
import cc.squirreljme.runtime.cldc.asm.ObjectAccess;
import cc.squirreljme.runtime.cldc.vki.Assembly;

/**
 * This class is the root of all class trees in Java.
 *
 * @since 2016/02/08
 */
@ImplementationNote("The Java compiler does not allow any final fields to " +
................................................................................
		throws CloneNotSupportedException
	{
		// If this is an array copy elements around
		Class<?> cl = this.getClass();
		if (cl.isArray())
		{
			// Need length of this array to recreate!
			int len = Assembly.arrayLength(this);
			
			// Allocate new array
			Object dest = ObjectAccess.arrayNew(cl, len);
			
			// Copy everything over
			System.arraycopy(this, 0, dest, 0, len);
			

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

79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
		if (__srcoff < 0 || __destoff < 0 || __copylen < 0)
			throw new IndexOutOfBoundsException(String.format("ZZ18 %d %d %d",
				__srcoff, __destoff, __copylen));
		
		// {@squirreljme.error ZZ19 Copy operation would exceed the bounds of
		// the array. (Source offset; Source length; Destination offset;
		// Destination length; The copy length)}
		int srclen = ObjectAccess.arrayLength(__src),
			destlen = ObjectAccess.arrayLength(__dest);
		if (__srcoff + __copylen > srclen ||
			__destoff + __copylen > destlen)
			throw new IndexOutOfBoundsException(String.format(
				"ZZ19 %d %d %d %d %d", __srcoff, srclen, __destoff, destlen,
				__copylen));
		
		// {@squirreljme.error ZZ1a The source array type is not compatible







|
|







79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
		if (__srcoff < 0 || __destoff < 0 || __copylen < 0)
			throw new IndexOutOfBoundsException(String.format("ZZ18 %d %d %d",
				__srcoff, __destoff, __copylen));
		
		// {@squirreljme.error ZZ19 Copy operation would exceed the bounds of
		// the array. (Source offset; Source length; Destination offset;
		// Destination length; The copy length)}
		int srclen = Assembly.arrayLength(__src),
			destlen = Assembly.arrayLength(__dest);
		if (__srcoff + __copylen > srclen ||
			__destoff + __copylen > destlen)
			throw new IndexOutOfBoundsException(String.format(
				"ZZ19 %d %d %d %d %d", __srcoff, srclen, __destoff, destlen,
				__copylen));
		
		// {@squirreljme.error ZZ1a The source array type is not compatible

Changes to runt/libs/springcoat-vm/cc/squirreljme/vm/springcoat/SpringThreadWorker.java.

1119
1120
1121
1122
1123
1124
1125





1126
1127
1128
1129
1130
1131
1132
....
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
		
		// Debug
		/*todo.DEBUG.note("Call native %s", __func);*/
		
		// Depends on the function
		switch (__func)
		{





				// Gets the raw bits for the given double value
			case "cc/squirreljme/runtime/cldc/vki/Assembly::" +
				"doubleToRawLongBits:(D)J":
				return Double.doubleToRawLongBits((Double)__args[0]);
				
				// Float to raw int bits
			case "cc/squirreljme/runtime/cldc/vki/Assembly::" +
................................................................................
				
				// Allocate object but do not construct it
			case "cc/squirreljme/runtime/cldc/asm/ObjectAccess::" +
				"allocateObject:(Ljava/lang/String;)Ljava/lang/Object;":
				return this.allocateObject(this.loadClass(
					new ClassName(this.<String>asNativeObject(
					String.class, ((SpringObject)__args[0])))));
				
				// Return the length of the array
			case "cc/squirreljme/runtime/cldc/asm/ObjectAccess::" +
				"arrayLength:(Ljava/lang/Object;)I":
				return ((SpringArrayObject)__args[0]).length();
			
				// Allocate array of a given class
			case "cc/squirreljme/runtime/cldc/asm/ObjectAccess::" +
				"arrayNew:(Ljava/lang/Class;I)Ljava/lang/Object;":
				{
					// Cannot do a reverse lookup
					SpringMachine machine = this.machine;







>
>
>
>
>







 







<
<
<
<
<







1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
....
1480
1481
1482
1483
1484
1485
1486





1487
1488
1489
1490
1491
1492
1493
		
		// Debug
		/*todo.DEBUG.note("Call native %s", __func);*/
		
		// Depends on the function
		switch (__func)
		{
				// Return the length of the array
			case "cc/squirreljme/runtime/cldc/vki/Assembly::" +
				"arrayLength:(Ljava/lang/Object;)I":
				return ((SpringArrayObject)__args[0]).length();
				
				// Gets the raw bits for the given double value
			case "cc/squirreljme/runtime/cldc/vki/Assembly::" +
				"doubleToRawLongBits:(D)J":
				return Double.doubleToRawLongBits((Double)__args[0]);
				
				// Float to raw int bits
			case "cc/squirreljme/runtime/cldc/vki/Assembly::" +
................................................................................
				
				// Allocate object but do not construct it
			case "cc/squirreljme/runtime/cldc/asm/ObjectAccess::" +
				"allocateObject:(Ljava/lang/String;)Ljava/lang/Object;":
				return this.allocateObject(this.loadClass(
					new ClassName(this.<String>asNativeObject(
					String.class, ((SpringObject)__args[0])))));





			
				// Allocate array of a given class
			case "cc/squirreljme/runtime/cldc/asm/ObjectAccess::" +
				"arrayNew:(Ljava/lang/Class;I)Ljava/lang/Object;":
				{
					// Cannot do a reverse lookup
					SpringMachine machine = this.machine;