Check-in [5ae3cf6070]

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

Overview
Comment:Do not check bounds in String.charAt(), allow the exception to be thrown; Use System.arraycopy() in ByteArrayInputStream as it can be native; Use full native copies in System.arraycopy() and Arrays.copyOf(); Have a branch specifically for primitive types in System.arraycopy(); Add some pre-checks to optimize away everything else.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | wip-midlevel
Files: files | file ages | folders
SHA1: 5ae3cf6070f0aaabba63082ded658db54f53928b
User & Date: stephanie.gawroriski 2020-06-29 03:25:13
Context
2020-06-30
01:28
More test fixes and functionality; Cleanup threads which have been terminated; Hide the terminated variable; Change order of thread initialization, enter main then create the thread instance so we are not quickly terminated this is so that threads are only terminated once. check-in: b3686a37ce user: stephanie.gawroriski tags: wip-midlevel
2020-06-29
03:25
Do not check bounds in String.charAt(), allow the exception to be thrown; Use System.arraycopy() in ByteArrayInputStream as it can be native; Use full native copies in System.arraycopy() and Arrays.copyOf(); Have a branch specifically for primitive types in System.arraycopy(); Add some pre-checks to optimize away everything else. check-in: 5ae3cf6070 user: stephanie.gawroriski tags: wip-midlevel
02:28
Correct clearing again. check-in: f600bc6e86 user: stephanie.gawroriski tags: wip-midlevel
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to modules/cldc-compact/src/main/java/java/io/ByteArrayInputStream.java.

157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
...
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
				read = count - pos;
			
			// Do not exceed this
			if (len < read)
				read = len;
			
			// Copy bytes
			for (int i = 0; i < len; i++)
				__b[i] = buf[pos++];
			
			// Store new position
			this.pos = pos;
			
			if (read == 0)
				return (pos >= count ? -1 : 0);
			return read;
................................................................................
				read = count - pos;
			
			// Do not exceed this
			if (__l < read)
				read = __l;
			
			// Copy bytes
			for (int i = 0; i < read; i++)
				__b[__o++] = buf[pos++];
			
			// Store new position
			this.pos = pos;
			
			if (read == 0)
				return (pos >= count ? -1 : 0);
			return read;







|
|







 







|
|







157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
...
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
				read = count - pos;
			
			// Do not exceed this
			if (len < read)
				read = len;
			
			// Copy bytes
			System.arraycopy(buf, pos, __b, 0, len);
			pos += len;
			
			// Store new position
			this.pos = pos;
			
			if (read == 0)
				return (pos >= count ? -1 : 0);
			return read;
................................................................................
				read = count - pos;
			
			// Do not exceed this
			if (__l < read)
				read = __l;
			
			// Copy bytes
			System.arraycopy(buf, pos, __b, __o, read);
			pos += read;
			
			// Store new position
			this.pos = pos;
			
			if (read == 0)
				return (pos >= count ? -1 : 0);
			return read;

Changes to modules/cldc-compact/src/main/java/java/lang/String.java.

322
323
324
325
326
327
328



329
330



331
332



333
334
335
336
337
338
339
	 * {@inheritDoc}
	 * @since 2018/09/20
	 */
	@Override
	public char charAt(int __i)
		throws IndexOutOfBoundsException
	{



		char[] chars = this._chars;
		if (__i < 0 || __i >= chars.length)



			throw new IndexOutOfBoundsException("IOOB " + __i);
		return chars[__i];



	}
	
	/**
	 * Compares the character values of this string and compares it to the
	 * character values of the other string.
	 *
	 * Smaller strings always precede longer strings.







>
>
>
|
<
>
>
>
|
<
>
>
>







322
323
324
325
326
327
328
329
330
331
332

333
334
335
336

337
338
339
340
341
342
343
344
345
346
	 * {@inheritDoc}
	 * @since 2018/09/20
	 */
	@Override
	public char charAt(int __i)
		throws IndexOutOfBoundsException
	{
		// Rather than bounds checking, directly try to access the array
		try
		{
			return this._chars[__i];

		}
		
		// We must ensure that the correct exception is thrown here
		catch (ArrayIndexOutOfBoundsException e)

		{
			throw new StringIndexOutOfBoundsException(__i);
		}
	}
	
	/**
	 * Compares the character values of this string and compares it to the
	 * character values of the other string.
	 *
	 * Smaller strings always precede longer strings.

Changes to modules/cldc-compact/src/main/java/java/lang/System.java.

8
9
10
11
12
13
14


15
16
17
18
19
20
21
..
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
122
123
124


125
126
127
128


129
130
131
132


133
134
135
136










137
138
139
140
141
142
143
// See license.mkd for licensing and copyright information.
// ---------------------------------------------------------------------------

package java.lang;

import cc.squirreljme.jvm.mle.ObjectShelf;
import cc.squirreljme.jvm.mle.RuntimeShelf;


import cc.squirreljme.jvm.mle.constants.StandardPipeType;
import cc.squirreljme.jvm.mle.constants.VMDescriptionType;
import cc.squirreljme.runtime.cldc.SquirrelJME;
import cc.squirreljme.runtime.cldc.i18n.DefaultLocale;
import cc.squirreljme.runtime.cldc.io.CodecFactory;
import cc.squirreljme.runtime.cldc.io.ConsoleOutputStream;
import cc.squirreljme.runtime.cldc.lang.LineEndingUtils;
................................................................................
			destLen = ObjectShelf.arrayLength(__dest);
		if (__srcOff + __copyLen > srcLen ||
			__destOff + __copyLen > destLen)
			throw new IndexOutOfBoundsException(String.format(
				"ZZ1x %d %d %d %d %d", __srcOff, srcLen, __destOff, destLen,
				__copyLen));
		




		// {@squirreljme.error ZZ1y The source array type is not compatible
		// with destination array. (The source array; The destination array)}
		if (!__dest.getClass().isAssignableFrom(__src.getClass()))

			throw new ArrayStoreException(String.format(
				"ZZ1y %s %s", __src, __dest));
		










		// These offsets for the loops are the same
		int i = __srcOff,
			o = __destOff,
			end = __srcOff + __copyLen;
		
		// Copy depending on the type











		if (__src instanceof boolean[])
			for (boolean[] s = (boolean[])__src, d = (boolean[])__dest;
				i < end; i++, o++)
			d[o] = s[i];


		else if (__src instanceof byte[])
			for (byte[] s = (byte[])__src, d = (byte[])__dest;
				i < end; i++, o++)
			d[o] = s[i];


		else if (__src instanceof short[])
			for (short[] s = (short[])__src, d = (short[])__dest;
				i < end; i++, o++)
			d[o] = s[i];


		else if (__src instanceof char[])
			ObjectShelf.arrayCopy((char[])__src, __srcOff,
				(char[])__dest, __destOff, __copyLen);


		else if (__src instanceof int[])
			for (int[] s = (int[])__src, d = (int[])__dest;
				i < end; i++, o++)
			d[o] = s[i];


		else if (__src instanceof long[])
			for (long[] s = (long[])__src, d = (long[])__dest;
				i < end; i++, o++)
			d[o] = s[i];


		else if (__src instanceof float[])
			for (float[] s = (float[])__src, d = (float[])__dest;
				i < end; i++, o++)
			d[o] = s[i];


		else if (__src instanceof double[])
			for (double[] s = (double[])__src, d = (double[])__dest;
				i < end; i++, o++)
			d[o] = s[i];










		else
			for (Object[] s = (Object[])__src, d = (Object[])__dest;
				i < end; i++, o++)
			d[o] = s[i];
	}
	
	/**







>
>







 







>
>
>
>


<
>



>
>
>
>
>
>
>
>
>
>





<
>
>
>
>
>
>
>
>
>
>
>
|
<
<
<
>
>
|
<
<
<
>
>
|
<
<
<
>
>
|
|
|
>
>
|
<
<
<
>
>
|
<
<
<
>
>
|
<
<
<
>
>
|
<
<
<
>
>
>
>
>
>
>
>
>
>







8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
..
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
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
151
152



153
154
155



156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
// See license.mkd for licensing and copyright information.
// ---------------------------------------------------------------------------

package java.lang;

import cc.squirreljme.jvm.mle.ObjectShelf;
import cc.squirreljme.jvm.mle.RuntimeShelf;
import cc.squirreljme.jvm.mle.TypeShelf;
import cc.squirreljme.jvm.mle.brackets.TypeBracket;
import cc.squirreljme.jvm.mle.constants.StandardPipeType;
import cc.squirreljme.jvm.mle.constants.VMDescriptionType;
import cc.squirreljme.runtime.cldc.SquirrelJME;
import cc.squirreljme.runtime.cldc.i18n.DefaultLocale;
import cc.squirreljme.runtime.cldc.io.CodecFactory;
import cc.squirreljme.runtime.cldc.io.ConsoleOutputStream;
import cc.squirreljme.runtime.cldc.lang.LineEndingUtils;
................................................................................
			destLen = ObjectShelf.arrayLength(__dest);
		if (__srcOff + __copyLen > srcLen ||
			__destOff + __copyLen > destLen)
			throw new IndexOutOfBoundsException(String.format(
				"ZZ1x %d %d %d %d %d", __srcOff, srcLen, __destOff, destLen,
				__copyLen));
		
		// Get both respective classes
		Class<?> srcClass = __src.getClass();
		Class<?> destClass = __dest.getClass();
		
		// {@squirreljme.error ZZ1y The source array type is not compatible
		// with destination array. (The source array; The destination array)}

		if (!destClass.isAssignableFrom(srcClass))
			throw new ArrayStoreException(String.format(
				"ZZ1y %s %s", __src, __dest));
		
		// If we are copying nothing then we need not even bother with anything
		// else and we do not have to check the array types as well.
		if (__copyLen == 0)
			return;
		
		// Also as well, if the source and destination are the same and the
		// offsets are the same then nothing will happen at all.
		if (__src == __dest && __srcOff == __destOff)
			return;
		
		// These offsets for the loops are the same
		int i = __srcOff,
			o = __destOff,
			end = __srcOff + __copyLen;
		

		// We can use the native type system within MLE to knock off a few
		// branch possibilities
		TypeBracket srcType = TypeShelf.classToType(srcClass);
		TypeBracket component = TypeShelf.component(srcType);
		
		// Primitive types can be copied at full speed as they do not require
		// any references are otherwise to be counted or garbage collection to
		// be managed
		if (TypeShelf.isPrimitive(component))
		{
			// More common primitives
			if (__src instanceof byte[])



				ObjectShelf.arrayCopy((byte[])__src, __srcOff,
					(byte[])__dest, __destOff, __copyLen);
			else if (__src instanceof char[])



				ObjectShelf.arrayCopy((char[])__src, __srcOff,
					(char[])__dest, __destOff, __copyLen);
			else if (__src instanceof int[])



				ObjectShelf.arrayCopy((int[])__src, __srcOff,
					(int[])__dest, __destOff, __copyLen);
			else if (__src instanceof short[])
				ObjectShelf.arrayCopy((short[])__src, __srcOff,
					(short[])__dest, __destOff, __copyLen);
			
			// Less common types
			else if (__src instanceof boolean[])



				ObjectShelf.arrayCopy((boolean[])__src, __srcOff,
					(boolean[])__dest, __destOff, __copyLen);
			else if (__src instanceof long[])



				ObjectShelf.arrayCopy((long[])__src, __srcOff,
					(long[])__dest, __destOff, __copyLen);
			else if (__src instanceof float[])



				ObjectShelf.arrayCopy((float[])__src, __srcOff,
					(float[])__dest, __destOff, __copyLen);
			else if (__src instanceof double[])



				ObjectShelf.arrayCopy((double[])__src, __srcOff,
					(double[])__dest, __destOff, __copyLen);
			
			// {@squirreljme.error ZZ1h Not a primitive array type.}
			else
				throw new Error("ZZ1h");
		}
		
		// There is no native handler for manual object array copies due to
		// references and otherwise
		else
			for (Object[] s = (Object[])__src, d = (Object[])__dest;
				i < end; i++, o++)
			d[o] = s[i];
	}
	
	/**

Changes to modules/cldc-compact/src/main/java/java/util/Arrays.java.

364
365
366
367
368
369
370
371
372

373
374
375
376
377
378
379
...
389
390
391
392
393
394
395
396
397

398
399
400
401
402
403
404
...
414
415
416
417
418
419
420
421
422

423
424
425
426
427
428
429
...
439
440
441
442
443
444
445
446
447

448
449
450
451
452
453
454
...
490
491
492
493
494
495
496
497
498

499
500
501
502
503
504
505
...
515
516
517
518
519
520
521
522
523

524
525
526
527
528
529
530
...
540
541
542
543
544
545
546
547
548

549
550
551
552
553
554
555
	{
		if (__src == null)
			throw new NullPointerException("NARG");
		if (__newLen < 0)
			throw new NegativeArraySizeException("NASE");
		
		byte[] rv = new byte[__newLen];
		for (int i = 0, n = Math.min(__newLen, __src.length); i < n; i++)
			rv[i] = __src[i];

		
		return rv;
	}
	
	/**
	 * Returns a new copy of the given array of the given length.
	 *
................................................................................
	{
		if (__src == null)
			throw new NullPointerException("NARG");
		if (__newLen < 0)
			throw new NegativeArraySizeException("NASE");
		
		short[] rv = new short[__newLen];
		for (int i = 0, n = Math.min(__newLen, __src.length); i < n; i++)
			rv[i] = __src[i];

		
		return rv;
	}
	
	/**
	 * Returns a new copy of the given array of the given length.
	 *
................................................................................
	{
		if (__src == null)
			throw new NullPointerException("NARG");
		if (__newLen < 0)
			throw new NegativeArraySizeException("NASE");
		
		int[] rv = new int[__newLen];
		for (int i = 0, n = Math.min(__newLen, __src.length); i < n; i++)
			rv[i] = __src[i];

		
		return rv;
	}
	
	/**
	 * Returns a new copy of the given array of the given length.
	 *
................................................................................
	{
		if (__src == null)
			throw new NullPointerException("NARG");
		if (__newLen < 0)
			throw new NegativeArraySizeException("NASE");
		
		long[] rv = new long[__newLen];
		for (int i = 0, n = Math.min(__newLen, __src.length); i < n; i++)
			rv[i] = __src[i];

		
		return rv;
	}
	
	/**
	 * Returns a new copy of the given array of the given length.
	 *
................................................................................
	{
		if (__src == null)
			throw new NullPointerException("NARG");
		if (__newLen < 0)
			throw new NegativeArraySizeException("NASE");
		
		float[] rv = new float[__newLen];
		for (int i = 0, n = Math.min(__newLen, __src.length); i < n; i++)
			rv[i] = __src[i];

		
		return rv;
	}
	
	/**
	 * Returns a new copy of the given array of the given length.
	 *
................................................................................
	{
		if (__src == null)
			throw new NullPointerException("NARG");
		if (__newLen < 0)
			throw new NegativeArraySizeException("NASE");
		
		double[] rv = new double[__newLen];
		for (int i = 0, n = Math.min(__newLen, __src.length); i < n; i++)
			rv[i] = __src[i];

		
		return rv;
	}
	
	/**
	 * Returns a new copy of the given array of the given length.
	 *
................................................................................
	{
		if (__src == null)
			throw new NullPointerException("NARG");
		if (__newLen < 0)
			throw new NegativeArraySizeException("NASE");
		
		boolean[] rv = new boolean[__newLen];
		for (int i = 0, n = Math.min(__newLen, __src.length); i < n; i++)
			rv[i] = __src[i];

		
		return rv;
	}
	
	/**
	 * Checks if both arrays are equal to each other.
	 *







|
|
>







 







|
|
>







 







|
|
>







 







|
|
>







 







|
|
>







 







|
|
>







 







|
|
>







364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
...
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
...
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
...
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
...
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
...
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
...
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
	{
		if (__src == null)
			throw new NullPointerException("NARG");
		if (__newLen < 0)
			throw new NegativeArraySizeException("NASE");
		
		byte[] rv = new byte[__newLen];
		
		ObjectShelf.arrayCopy(__src, 0, rv, 0,
			Math.min(__newLen, __src.length));
		
		return rv;
	}
	
	/**
	 * Returns a new copy of the given array of the given length.
	 *
................................................................................
	{
		if (__src == null)
			throw new NullPointerException("NARG");
		if (__newLen < 0)
			throw new NegativeArraySizeException("NASE");
		
		short[] rv = new short[__newLen];
		
		ObjectShelf.arrayCopy(__src, 0, rv, 0,
			Math.min(__newLen, __src.length));
		
		return rv;
	}
	
	/**
	 * Returns a new copy of the given array of the given length.
	 *
................................................................................
	{
		if (__src == null)
			throw new NullPointerException("NARG");
		if (__newLen < 0)
			throw new NegativeArraySizeException("NASE");
		
		int[] rv = new int[__newLen];
		
		ObjectShelf.arrayCopy(__src, 0, rv, 0,
			Math.min(__newLen, __src.length));
		
		return rv;
	}
	
	/**
	 * Returns a new copy of the given array of the given length.
	 *
................................................................................
	{
		if (__src == null)
			throw new NullPointerException("NARG");
		if (__newLen < 0)
			throw new NegativeArraySizeException("NASE");
		
		long[] rv = new long[__newLen];
		
		ObjectShelf.arrayCopy(__src, 0, rv, 0,
			Math.min(__newLen, __src.length));
		
		return rv;
	}
	
	/**
	 * Returns a new copy of the given array of the given length.
	 *
................................................................................
	{
		if (__src == null)
			throw new NullPointerException("NARG");
		if (__newLen < 0)
			throw new NegativeArraySizeException("NASE");
		
		float[] rv = new float[__newLen];
		
		ObjectShelf.arrayCopy(__src, 0, rv, 0,
			Math.min(__newLen, __src.length));
		
		return rv;
	}
	
	/**
	 * Returns a new copy of the given array of the given length.
	 *
................................................................................
	{
		if (__src == null)
			throw new NullPointerException("NARG");
		if (__newLen < 0)
			throw new NegativeArraySizeException("NASE");
		
		double[] rv = new double[__newLen];
		
		ObjectShelf.arrayCopy(__src, 0, rv, 0,
			Math.min(__newLen, __src.length));
		
		return rv;
	}
	
	/**
	 * Returns a new copy of the given array of the given length.
	 *
................................................................................
	{
		if (__src == null)
			throw new NullPointerException("NARG");
		if (__newLen < 0)
			throw new NegativeArraySizeException("NASE");
		
		boolean[] rv = new boolean[__newLen];
		
		ObjectShelf.arrayCopy(__src, 0, rv, 0,
			Math.min(__newLen, __src.length));
		
		return rv;
	}
	
	/**
	 * Checks if both arrays are equal to each other.
	 *