# HG changeset patch # Parent 405bd0d1f7be09d4b0ffca1df953103a3f044759 diff --git a/src/java.base/share/classes/java/lang/invoke/LambdaFormEditor.java b/src/java.base/share/classes/java/lang/invoke/LambdaFormEditor.java --- a/src/java.base/share/classes/java/lang/invoke/LambdaFormEditor.java +++ b/src/java.base/share/classes/java/lang/invoke/LambdaFormEditor.java @@ -61,7 +61,6 @@ * Sequences that are simple (short enough and with small enough values) pack into a 64-bit long. */ private static final class Transform { - final long packedBytes; final byte[] fullBytes; final LambdaForm result; // result of transform, or null, if there is none available @@ -76,82 +75,28 @@ //maybe add more for guard with test, catch exception, pointwise type conversions } - private static final boolean STRESS_TEST = false; // turn on to disable most packing - private static final int - PACKED_BYTE_SIZE = (STRESS_TEST ? 2 : 4), - PACKED_BYTE_MASK = (1 << PACKED_BYTE_SIZE) - 1, - PACKED_BYTE_MAX_LENGTH = (STRESS_TEST ? 3 : 64 / PACKED_BYTE_SIZE); - - private static long packedBytes(byte[] bytes) { - if (bytes.length > PACKED_BYTE_MAX_LENGTH) return 0; - long pb = 0; - int bitset = 0; - for (int i = 0; i < bytes.length; i++) { - int b = bytes[i] & 0xFF; - bitset |= b; - pb |= (long)b << (i * PACKED_BYTE_SIZE); - } - if (!inRange(bitset)) - return 0; - return pb; - } - private static long packedBytes(int b0, int b1) { - assert(inRange(b0 | b1)); - return ( (b0 << 0*PACKED_BYTE_SIZE) - | (b1 << 1*PACKED_BYTE_SIZE)); - } - private static long packedBytes(int b0, int b1, int b2) { - assert(inRange(b0 | b1 | b2)); - return ( (b0 << 0*PACKED_BYTE_SIZE) - | (b1 << 1*PACKED_BYTE_SIZE) - | (b2 << 2*PACKED_BYTE_SIZE)); - } - private static long packedBytes(int b0, int b1, int b2, int b3) { - assert(inRange(b0 | b1 | b2 | b3)); - return ( (b0 << 0*PACKED_BYTE_SIZE) - | (b1 << 1*PACKED_BYTE_SIZE) - | (b2 << 2*PACKED_BYTE_SIZE) - | (b3 << 3*PACKED_BYTE_SIZE)); - } - private static boolean inRange(int bitset) { - assert((bitset & 0xFF) == bitset); // incoming values must fit in *unsigned* byte - return ((bitset & ~PACKED_BYTE_MASK) == 0); - } private static byte[] fullBytes(int... byteValues) { byte[] bytes = new byte[byteValues.length]; int i = 0; for (int bv : byteValues) { bytes[i++] = bval(bv); } - assert(packedBytes(bytes) == 0); return bytes; } private byte byteAt(int i) { - long pb = packedBytes; - if (pb == 0) { - if (i >= fullBytes.length) return 0; - return fullBytes[i]; - } - assert(fullBytes == null); - if (i > PACKED_BYTE_MAX_LENGTH) return 0; - int pos = (i * PACKED_BYTE_SIZE); - return (byte)((pb >>> pos) & PACKED_BYTE_MASK); + if (i >= fullBytes.length) return 0; + return fullBytes[i]; } Kind kind() { return Kind.values()[byteAt(0)]; } - private Transform(long packedBytes, byte[] fullBytes, LambdaForm result) { - this.packedBytes = packedBytes; + private Transform(byte[] fullBytes, LambdaForm result) { this.fullBytes = fullBytes; this.result = result; } - private Transform(long packedBytes) { - this(packedBytes, null, null); - assert(packedBytes != 0); - } private Transform(byte[] fullBytes) { - this(0, fullBytes, null); + this(fullBytes, null); } private static byte bval(int b) { @@ -163,24 +108,15 @@ } static Transform of(Kind k, int b1) { byte b0 = bval(k); - if (inRange(b0 | b1)) - return new Transform(packedBytes(b0, b1)); - else - return new Transform(fullBytes(b0, b1)); + return new Transform(fullBytes(b0, b1)); } static Transform of(Kind k, int b1, int b2) { byte b0 = (byte) k.ordinal(); - if (inRange(b0 | b1 | b2)) - return new Transform(packedBytes(b0, b1, b2)); - else - return new Transform(fullBytes(b0, b1, b2)); + return new Transform(fullBytes(b0, b1, b2)); } static Transform of(Kind k, int b1, int b2, int b3) { byte b0 = (byte) k.ordinal(); - if (inRange(b0 | b1 | b2 | b3)) - return new Transform(packedBytes(b0, b1, b2, b3)); - else - return new Transform(fullBytes(b0, b1, b2, b3)); + return new Transform(fullBytes(b0, b1, b2, b3)); } private static final byte[] NO_BYTES = {}; static Transform of(Kind k, int... b123) { @@ -202,15 +138,11 @@ for (byte bv : b456) { fullBytes[i++] = bv; } - long packedBytes = packedBytes(fullBytes); - if (packedBytes != 0) - return new Transform(packedBytes); - else - return new Transform(fullBytes); + return new Transform(fullBytes); } Transform withResult(LambdaForm result) { - return new Transform(this.packedBytes, this.fullBytes, result); + return new Transform(this.fullBytes, result); } @Override @@ -218,29 +150,15 @@ return obj instanceof Transform && equals((Transform)obj); } public boolean equals(Transform that) { - return this.packedBytes == that.packedBytes && Arrays.equals(this.fullBytes, that.fullBytes); + return Arrays.equals(this.fullBytes, that.fullBytes); } @Override public int hashCode() { - if (packedBytes != 0) { - assert(fullBytes == null); - return Long.hashCode(packedBytes); - } return Arrays.hashCode(fullBytes); } @Override public String toString() { StringBuilder buf = new StringBuilder(); - long bits = packedBytes; - if (bits != 0) { - buf.append("("); - while (bits != 0) { - buf.append(bits & PACKED_BYTE_MASK); - bits >>>= PACKED_BYTE_SIZE; - if (bits != 0) buf.append(","); - } - buf.append(")"); - } if (fullBytes != null) { buf.append("unpacked"); buf.append(Arrays.toString(fullBytes)); @@ -290,7 +208,6 @@ */ private LambdaForm putInCache(Transform key, LambdaForm form) { key = key.withResult(form); - if (COUNT_EVENTS && key.packedBytes == 0) bump(EC_editorCacheUnpacked); for (int pass = 0; ; pass++) { Object c = lambdaForm.transformCache; if (c instanceof ConcurrentHashMap) { @@ -898,5 +815,4 @@ }; private static final EventCounter EC_editorCache_sizeBig = eventCounter("editorCache.sizeBig"); private static final EventCounter EC_editorCache_probes = eventCounter("editorCache.probes"); - private static final EventCounter EC_editorCacheUnpacked = eventCounter("editorCacheUnpacked"); }