Check-in [d2e5d8e2e9]

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

Overview
Comment:Move memory information to system calls.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:d2e5d8e2e9cfe47cb3916fb1e5153aaf25c96030
User & Date: stephanie.gawroriski 2019-05-23 23:07:07
Context
2019-05-23
23:14
Add GARBAGE_COLLECT system call and remove MemoryAccess (not used anymore). check-in: 7434d31525 user: stephanie.gawroriski tags: trunk
23:07
Move memory information to system calls. check-in: d2e5d8e2e9 user: stephanie.gawroriski tags: trunk
18:29
Remove the UniversalAPI and UniversalCallback stuff. check-in: 7a1c68e49d user: stephanie.gawroriski tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

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

1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055



























1056
1057
1058
1059
1060
1061
1062
					}
					
					// Always succeeds
					err = 0;
				}
				break;
			
			// Current wall clock milliseconds (low).
			case SystemCallIndex.TIME_LO_MILLI_WALL:
				{
					rv = (int)(System.currentTimeMillis());
					err = 0;
				}
				break;

			// Current wall clock milliseconds (high).
			case SystemCallIndex.TIME_HI_MILLI_WALL:
				{
					rv = (int)(System.currentTimeMillis() >>> 32);
					err = 0;
				}
				break;

			// Current monotonic clock nanoseconds (low).
			case SystemCallIndex.TIME_LO_NANO_MONO:
				{
					rv = (int)(System.nanoTime());
					err = 0;
				}
				break;

			// Current monotonic clock nanoseconds (high).
			case SystemCallIndex.TIME_HI_NANO_MONO:
				{
					rv = (int)(System.nanoTime() >>> 32);
					err = 0;
				}
				break;



























			
			default:
				// Returns no value but sets an error
				rv = -1;
				err = SystemCallError.UNSUPPORTED_SYSTEM_CALL;
				
				// If the ID is valid then a bad array access will be used







|







|







|







|






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







1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
					}
					
					// Always succeeds
					err = 0;
				}
				break;
			
				// Current wall clock milliseconds (low).
			case SystemCallIndex.TIME_LO_MILLI_WALL:
				{
					rv = (int)(System.currentTimeMillis());
					err = 0;
				}
				break;

				// Current wall clock milliseconds (high).
			case SystemCallIndex.TIME_HI_MILLI_WALL:
				{
					rv = (int)(System.currentTimeMillis() >>> 32);
					err = 0;
				}
				break;

				// Current monotonic clock nanoseconds (low).
			case SystemCallIndex.TIME_LO_NANO_MONO:
				{
					rv = (int)(System.nanoTime());
					err = 0;
				}
				break;

				// Current monotonic clock nanoseconds (high).
			case SystemCallIndex.TIME_HI_NANO_MONO:
				{
					rv = (int)(System.nanoTime() >>> 32);
					err = 0;
				}
				break;
			
				// VM information: Memory free bytes
			case SystemCallIndex.VMI_MEM_FREE:
				{
					rv = (int)Math.min(Integer.MAX_VALUE,
						Runtime.getRuntime().freeMemory());
					err = 0;
				}
				break;
			
				// VM information: Memory used bytes
			case SystemCallIndex.VMI_MEM_USED:
				{
					rv = (int)Math.min(Integer.MAX_VALUE,
						Runtime.getRuntime().totalMemory());
					err = 0;
				}
				break;
			
				// VM information: Memory max bytes
			case SystemCallIndex.VMI_MEM_MAX:
				{
					rv = (int)Math.min(Integer.MAX_VALUE,
						Runtime.getRuntime().maxMemory());
					err = 0;
				}
				break;
			
			default:
				// Returns no value but sets an error
				rv = -1;
				err = SystemCallError.UNSUPPORTED_SYSTEM_CALL;
				
				// If the ID is valid then a bad array access will be used

Changes to runt/apis/cldc-compact/cc/squirreljme/runtime/cldc/asm/MemoryAccess.java.

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
	 *
	 * @since 2017/12/27
	 */
	private MemoryAccess()
	{
	}
	
	/**
	 * Returns the amount of memory that is available for the VM to use.
	 *
	 * @return The amount of free memory.
	 * @since 2018/10/14
	 */
	@Api(ApiLevel.LEVEL_SQUIRRELJME_0_2_0_20181225)
	public static final native long freeMemory();
	
	/**
	 * Performs or hints to the garbage collector that it should run.
	 *
	 * @since 2018/10/14
	 */
	@Api(ApiLevel.LEVEL_SQUIRRELJME_0_2_0_20181225)
	public static final native void gc();
	
	/**
	 * Returns the maximum amount of memory that the virtual machine will
	 * attempt to use, if there is no limit then {@link Long#MAX_VALUE} will
	 * be used.
	 *
	 * @return The maximum amount of memory available to the virtual machine.
	 * @since 2018/10/14
	 */
	@Api(ApiLevel.LEVEL_SQUIRRELJME_0_2_0_20181225)
	public static final native long maxMemory();
	
	/**
	 * Returns the total amount of memory that is being used by the virtual
	 * machine. This is a count of all the memory claimed by the virtual
	 * machine itself for its memory pools and such.
	 *
	 * @return The amount of memory being used by the virtual machine.
	 * @since 2018/10/14
	 */
	@Api(ApiLevel.LEVEL_SQUIRRELJME_0_2_0_20181225)
	public static final native long totalMemory();
}








<
<
<
<
<
<
<
<
<







|
<
<
<
<
|
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
26
27
28
29
30
31
32









33
34
35
36
37
38
39
40




41


















	 *
	 * @since 2017/12/27
	 */
	private MemoryAccess()
	{
	}
	









	/**
	 * Performs or hints to the garbage collector that it should run.
	 *
	 * @since 2018/10/14
	 */
	@Api(ApiLevel.LEVEL_SQUIRRELJME_0_2_0_20181225)
	public static final native void gc();
}























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

28
29
30
31
32
33
34
35


36










	 * Not used.
	 *
	 * @since 2019/05/23
	 */
	private SystemCallError()
	{
	}
}




















|
>
>
|
>
>
>
>
>
>
>
>
>
>
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
	 * Not used.
	 *
	 * @since 2019/05/23
	 */
	private SystemCallError()
	{
	}
	
	/**
	 * Returns the error state.
	 *
	 * @param __si The system call index.
	 * @return The error, 0 will be on success.
	 * @since 2019/05/23
	 */
	public static final int getError(short __si)
	{
		return Assembly.sysCallV(SystemCallIndex.ERROR_GET, __si);
	}
}

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

49
50
51
52
53
54
55















56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
	public static final short TIME_LO_NANO_MONO =
		5;
	
	/** Current monotonic clock nanoseconds (high). */
	@Api(ApiLevel.LEVEL_SQUIRRELJME_0_3_0_DEV)
	public static final short TIME_HI_NANO_MONO =
		6;















	
	/** System call count. */
	public static final int NUM_SYSCALLS =
		7;
	
	/**
	 * Not used.
	 *
	 * @since 2019/05/23
	 */
	private SystemCallIndex()
	{
	}
}








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



|











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
	public static final short TIME_LO_NANO_MONO =
		5;
	
	/** Current monotonic clock nanoseconds (high). */
	@Api(ApiLevel.LEVEL_SQUIRRELJME_0_3_0_DEV)
	public static final short TIME_HI_NANO_MONO =
		6;
	
	/** VM Information: Free memory in bytes. */
	@Api(ApiLevel.LEVEL_SQUIRRELJME_0_3_0_DEV)
	public static final short VMI_MEM_FREE =
		7;
	
	/** VM Information: Used memory in bytes. */
	@Api(ApiLevel.LEVEL_SQUIRRELJME_0_3_0_DEV)
	public static final short VMI_MEM_USED =
		8;
	
	/** VM Information: Max memory in bytes. */
	@Api(ApiLevel.LEVEL_SQUIRRELJME_0_3_0_DEV)
	public static final short VMI_MEM_MAX =
		9;
	
	/** System call count. */
	public static final int NUM_SYSCALLS =
		10;
	
	/**
	 * Not used.
	 *
	 * @since 2019/05/23
	 */
	private SystemCallIndex()
	{
	}
}

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

8
9
10
11
12
13
14



15
16
17
18
19
20
21
..
58
59
60
61
62
63
64
65



66
67
68
69
70
71
72
..
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
// See license.mkd for licensing and copyright information.
// ---------------------------------------------------------------------------

package java.lang;

import cc.squirreljme.runtime.cldc.asm.SystemAccess;
import cc.squirreljme.runtime.cldc.asm.MemoryAccess;




/**
 * This class contains information about the host memory environment along
 * with providing methods to perform garbage collection and exit the
 * virtual machine.
 *
 * @since 2018/10/14
................................................................................
	 * Returns the amount of memory that is free for the JVM to use.
	 *
	 * @return The amount of free memory.
	 * @since 2018/10/14
	 */
	public long freeMemory()
	{
		return MemoryAccess.freeMemory();



	}
	
	/**
	 * Indicates that the application should have garbage collection be
	 * performed. It is unspecified when garbage collection occurs.
	 *
	 * @since 2017/02/08
................................................................................
	 * be used.
	 *
	 * @return The maximum amount of memory available to the virtual machine.
	 * @since 2018/10/14
	 */
	public long maxMemory()
	{
		return MemoryAccess.maxMemory();



	}
	
	/**
	 * Returns the total amount of memory that is being used by the virtual
	 * machine. This is a count of all the memory claimed by the virtual
	 * machine itself for its memory pools and such.
	 *
	 * @return The amount of memory being used by the virtual machine.
	 * @since 2018/10/14
	 */
	public long totalMemory()
	{
		return MemoryAccess.totalMemory();



	}
	
	/**
	 * Returns the single instance of this class.
	 *
	 * Only a single runtime is valid and there will only be one.
	 *







>
>
>







 







|
>
>
>







 







|
>
>
>












|
>
>
>







8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
..
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
..
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
// See license.mkd for licensing and copyright information.
// ---------------------------------------------------------------------------

package java.lang;

import cc.squirreljme.runtime.cldc.asm.SystemAccess;
import cc.squirreljme.runtime.cldc.asm.MemoryAccess;
import cc.squirreljme.runtime.cldc.vki.Assembly;
import cc.squirreljme.runtime.cldc.vki.SystemCallError;
import cc.squirreljme.runtime.cldc.vki.SystemCallIndex;

/**
 * This class contains information about the host memory environment along
 * with providing methods to perform garbage collection and exit the
 * virtual machine.
 *
 * @since 2018/10/14
................................................................................
	 * Returns the amount of memory that is free for the JVM to use.
	 *
	 * @return The amount of free memory.
	 * @since 2018/10/14
	 */
	public long freeMemory()
	{
		int rv = Assembly.sysCallV(SystemCallIndex.VMI_MEM_FREE);
		if (0 != SystemCallError.getError(SystemCallIndex.VMI_MEM_FREE))
			return Integer.MAX_VALUE;
		return rv;
	}
	
	/**
	 * Indicates that the application should have garbage collection be
	 * performed. It is unspecified when garbage collection occurs.
	 *
	 * @since 2017/02/08
................................................................................
	 * be used.
	 *
	 * @return The maximum amount of memory available to the virtual machine.
	 * @since 2018/10/14
	 */
	public long maxMemory()
	{
		int rv = Assembly.sysCallV(SystemCallIndex.VMI_MEM_MAX);
		if (0 != SystemCallError.getError(SystemCallIndex.VMI_MEM_MAX))
			return Integer.MAX_VALUE;
		return rv;
	}
	
	/**
	 * Returns the total amount of memory that is being used by the virtual
	 * machine. This is a count of all the memory claimed by the virtual
	 * machine itself for its memory pools and such.
	 *
	 * @return The amount of memory being used by the virtual machine.
	 * @since 2018/10/14
	 */
	public long totalMemory()
	{
		int rv = Assembly.sysCallV(SystemCallIndex.VMI_MEM_USED);
		if (0 != SystemCallError.getError(SystemCallIndex.VMI_MEM_USED))
			return 0;
		return rv;
	}
	
	/**
	 * Returns the single instance of this class.
	 *
	 * Only a single runtime is valid and there will only be one.
	 *

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

1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
....
4216
4217
4218
4219
4220
4221
4222



























4223
4224
4225
4226
4227
4228
4229
					
				// Unresolve string pointer
			case "cc/squirreljme/runtime/cldc/asm/DebugAccess::" +
				"unresolveString:(Ljava/lang/String;)J":
				return this.machine.debugUnresolveString(
					this.<String>asNativeObject(String.class, __args[0]));
				
				// Free memory
			case "cc/squirreljme/runtime/cldc/asm/MemoryAccess::" +
				"freeMemory:()J":
				return Runtime.getRuntime().freeMemory();
				
				// Garbage collect suggestion
			case "cc/squirreljme/runtime/cldc/asm/MemoryAccess::" +
				"gc:()V":
				Runtime.getRuntime().gc();
				return null;
				
				// Max memory
			case "cc/squirreljme/runtime/cldc/asm/MemoryAccess::" +
				"maxMemory:()J":
				return Runtime.getRuntime().maxMemory();
				
				// Max memory
			case "cc/squirreljme/runtime/cldc/asm/MemoryAccess::" +
				"totalMemory:()J":
				return Runtime.getRuntime().totalMemory();
				
				// Accelerated graphics
			case "cc/squirreljme/runtime/cldc/asm/NativeDisplayAccess::" +
				"accelGfx:(I)Z":
				return this.machine.nativedisplay.accelGfx(
					(Integer)__args[0]);
				
				// Accelerated graphics operation
................................................................................
			// Current monotonic clock nanoseconds (high).
			case SystemCallIndex.TIME_HI_NANO_MONO:
				{
					rv = (int)(System.nanoTime() >>> 32);
					err = 0;
				}
				break;



























			
			default:
				// Returns no value but sets an error
				rv = -1;
				err = SystemCallError.UNSUPPORTED_SYSTEM_CALL;
				
				// If the ID is valid then a bad array access will be used







<
<
<
<
<






<
<
<
<
<
<
<
<
<
<







 







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







1364
1365
1366
1367
1368
1369
1370





1371
1372
1373
1374
1375
1376










1377
1378
1379
1380
1381
1382
1383
....
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
					
				// Unresolve string pointer
			case "cc/squirreljme/runtime/cldc/asm/DebugAccess::" +
				"unresolveString:(Ljava/lang/String;)J":
				return this.machine.debugUnresolveString(
					this.<String>asNativeObject(String.class, __args[0]));
				





				// Garbage collect suggestion
			case "cc/squirreljme/runtime/cldc/asm/MemoryAccess::" +
				"gc:()V":
				Runtime.getRuntime().gc();
				return null;
				










				// Accelerated graphics
			case "cc/squirreljme/runtime/cldc/asm/NativeDisplayAccess::" +
				"accelGfx:(I)Z":
				return this.machine.nativedisplay.accelGfx(
					(Integer)__args[0]);
				
				// Accelerated graphics operation
................................................................................
			// Current monotonic clock nanoseconds (high).
			case SystemCallIndex.TIME_HI_NANO_MONO:
				{
					rv = (int)(System.nanoTime() >>> 32);
					err = 0;
				}
				break;
			
				// VM information: Memory free bytes
			case SystemCallIndex.VMI_MEM_FREE:
				{
					rv = (int)Math.min(Integer.MAX_VALUE,
						Runtime.getRuntime().freeMemory());
					err = 0;
				}
				break;
			
				// VM information: Memory used bytes
			case SystemCallIndex.VMI_MEM_USED:
				{
					rv = (int)Math.min(Integer.MAX_VALUE,
						Runtime.getRuntime().totalMemory());
					err = 0;
				}
				break;
			
				// VM information: Memory max bytes
			case SystemCallIndex.VMI_MEM_MAX:
				{
					rv = (int)Math.min(Integer.MAX_VALUE,
						Runtime.getRuntime().maxMemory());
					err = 0;
				}
				break;
			
			default:
				// Returns no value but sets an error
				rv = -1;
				err = SystemCallError.UNSUPPORTED_SYSTEM_CALL;
				
				// If the ID is valid then a bad array access will be used