mirror of
https://github.com/honeymoose/OpenSearch.git
synced 2025-03-30 11:58:36 +00:00
Painless: Add tests to check for existence and correct detection of the special Java 9 optimizations: Indified String concat and MethodHandles#ArrayLengthHelper() (#24405)
This commit is contained in:
parent
691ec68a3c
commit
62fa7081b0
@ -112,8 +112,8 @@ public final class Def {
|
|||||||
private static final MethodHandle MAP_INDEX_NORMALIZE;
|
private static final MethodHandle MAP_INDEX_NORMALIZE;
|
||||||
/** pointer to {@link Def#listIndexNormalize}. */
|
/** pointer to {@link Def#listIndexNormalize}. */
|
||||||
private static final MethodHandle LIST_INDEX_NORMALIZE;
|
private static final MethodHandle LIST_INDEX_NORMALIZE;
|
||||||
/** factory for arraylength MethodHandle (intrinsic) from Java 9 */
|
/** factory for arraylength MethodHandle (intrinsic) from Java 9 (pkg-private for tests) */
|
||||||
private static final MethodHandle JAVA9_ARRAY_LENGTH_MH_FACTORY;
|
static final MethodHandle JAVA9_ARRAY_LENGTH_MH_FACTORY;
|
||||||
|
|
||||||
static {
|
static {
|
||||||
final Lookup lookup = MethodHandles.publicLookup();
|
final Lookup lookup = MethodHandles.publicLookup();
|
||||||
|
@ -19,6 +19,7 @@
|
|||||||
|
|
||||||
package org.elasticsearch.painless;
|
package org.elasticsearch.painless;
|
||||||
|
|
||||||
|
import org.apache.lucene.util.Constants;
|
||||||
import org.hamcrest.Matcher;
|
import org.hamcrest.Matcher;
|
||||||
|
|
||||||
import java.lang.invoke.MethodHandle;
|
import java.lang.invoke.MethodHandle;
|
||||||
@ -44,6 +45,7 @@ public class ArrayTests extends ArrayLikeObjectTestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void testArrayLengthHelper() throws Throwable {
|
public void testArrayLengthHelper() throws Throwable {
|
||||||
|
assertEquals(Constants.JRE_IS_MINIMUM_JAVA9, Def.JAVA9_ARRAY_LENGTH_MH_FACTORY != null);
|
||||||
assertArrayLength(2, new int[2]);
|
assertArrayLength(2, new int[2]);
|
||||||
assertArrayLength(3, new long[3]);
|
assertArrayLength(3, new long[3]);
|
||||||
assertArrayLength(4, new byte[4]);
|
assertArrayLength(4, new byte[4]);
|
||||||
|
@ -19,6 +19,8 @@
|
|||||||
|
|
||||||
package org.elasticsearch.painless;
|
package org.elasticsearch.painless;
|
||||||
|
|
||||||
|
import org.apache.lucene.util.Constants;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@ -249,4 +251,11 @@ public class StringTests extends ScriptTestCase {
|
|||||||
String rando = randomRealisticUnicodeOfLength(between(5, 1000));
|
String rando = randomRealisticUnicodeOfLength(between(5, 1000));
|
||||||
assertEquals(rando, exec("params.rando.encodeBase64().decodeBase64()", singletonMap("rando", rando), true));
|
assertEquals(rando, exec("params.rando.encodeBase64().decodeBase64()", singletonMap("rando", rando), true));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testJava9StringConcatBytecode() {
|
||||||
|
assumeTrue("Needs Java 9 to test indified String concat", Constants.JRE_IS_MINIMUM_JAVA9);
|
||||||
|
assertNotNull(WriterConstants.INDY_STRING_CONCAT_BOOTSTRAP_HANDLE);
|
||||||
|
assertBytecodeExists("String s = \"cat\"; return s + true + 'abc' + null;",
|
||||||
|
"INVOKEDYNAMIC concat(Ljava/lang/String;ZLjava/lang/String;Ljava/lang/Object;)Ljava/lang/String;");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user