From 1b10a14e8d26dcc197a359cb142a1e4eee8df87c Mon Sep 17 00:00:00 2001 From: Uwe Schindler Date: Fri, 13 May 2016 22:47:18 +0200 Subject: [PATCH] painless: build descriptor of array and field load/store in code; fix array index to adapt type not DEF --- .../org/elasticsearch/painless/WriterConstants.java | 9 --------- .../org/elasticsearch/painless/node/LDefArray.java | 13 +++++++------ .../org/elasticsearch/painless/node/LDefField.java | 9 +++++---- 3 files changed, 12 insertions(+), 19 deletions(-) diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/WriterConstants.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/WriterConstants.java index 8ad57c8fd8d..98aee5b7d90 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/WriterConstants.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/WriterConstants.java @@ -61,15 +61,6 @@ public final class WriterConstants { new Handle(Opcodes.H_INVOKESTATIC, Type.getInternalName(DefBootstrap.class), "bootstrap", DEF_BOOTSTRAP_TYPE.toMethodDescriptorString()); - public final static String DEF_DYNAMIC_LOAD_FIELD_DESC = - MethodType.methodType(Object.class, Object.class).toMethodDescriptorString(); - public final static String DEF_DYNAMIC_STORE_FIELD_DESC = - MethodType.methodType(void.class, Object.class, Object.class).toMethodDescriptorString(); - public final static String DEF_DYNAMIC_ARRAY_LOAD_DESC = - MethodType.methodType(Object.class, Object.class, Object.class).toMethodDescriptorString(); - public final static String DEF_DYNAMIC_ARRAY_STORE_DESC = - MethodType.methodType(void.class, Object.class, Object.class, Object.class).toMethodDescriptorString(); - public final static Method DEF_NOT_CALL = getAsmMethod(Object.class, "not", Object.class); public final static Method DEF_NEG_CALL = getAsmMethod(Object.class, "neg", Object.class); public final static Method DEF_MUL_CALL = getAsmMethod(Object.class, "mul", Object.class, Object.class); diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/LDefArray.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/LDefArray.java index 6b701a77728..48e39457df9 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/LDefArray.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/LDefArray.java @@ -23,11 +23,10 @@ import org.elasticsearch.painless.CompilerSettings; import org.elasticsearch.painless.Definition; import org.elasticsearch.painless.DefBootstrap; import org.elasticsearch.painless.Variables; +import org.objectweb.asm.Type; import org.objectweb.asm.commons.GeneratorAdapter; import static org.elasticsearch.painless.WriterConstants.DEF_BOOTSTRAP_HANDLE; -import static org.elasticsearch.painless.WriterConstants.DEF_DYNAMIC_ARRAY_LOAD_DESC; -import static org.elasticsearch.painless.WriterConstants.DEF_DYNAMIC_ARRAY_STORE_DESC; /** * Represents an array load/store or shortcut on a def type. (Internal only.) @@ -45,8 +44,8 @@ final class LDefArray extends ALink { @Override ALink analyze(final CompilerSettings settings, final Definition definition, final Variables variables) { - index.expected = definition.objectType; index.analyze(settings, definition, variables); + index.expected = index.actual; index = index.cast(settings, definition, variables); after = definition.defType; @@ -61,14 +60,16 @@ final class LDefArray extends ALink { @Override void load(final CompilerSettings settings, final Definition definition, final GeneratorAdapter adapter) { + final String desc = Type.getMethodDescriptor(definition.defType.type, definition.defType.type, index.actual.type); adapter.visitInvokeDynamicInsn( - "arrayLoad", DEF_DYNAMIC_ARRAY_LOAD_DESC, DEF_BOOTSTRAP_HANDLE, new Object[] { DefBootstrap.ARRAY_LOAD }); - + "arrayLoad", desc, DEF_BOOTSTRAP_HANDLE, new Object[] { DefBootstrap.ARRAY_LOAD }); } @Override void store(final CompilerSettings settings, final Definition definition, final GeneratorAdapter adapter) { + final String desc = Type.getMethodDescriptor(definition.voidType.type, definition.defType.type, + index.actual.type, definition.defType.type); adapter.visitInvokeDynamicInsn( - "arrayStore", DEF_DYNAMIC_ARRAY_STORE_DESC, DEF_BOOTSTRAP_HANDLE, new Object[] { DefBootstrap.ARRAY_STORE }); + "arrayStore", desc, DEF_BOOTSTRAP_HANDLE, new Object[] { DefBootstrap.ARRAY_STORE }); } } diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/LDefField.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/LDefField.java index f8b2f3be83a..b5d7bb8b37b 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/LDefField.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/LDefField.java @@ -23,11 +23,10 @@ import org.elasticsearch.painless.CompilerSettings; import org.elasticsearch.painless.Definition; import org.elasticsearch.painless.DefBootstrap; import org.elasticsearch.painless.Variables; +import org.objectweb.asm.Type; import org.objectweb.asm.commons.GeneratorAdapter; import static org.elasticsearch.painless.WriterConstants.DEF_BOOTSTRAP_HANDLE; -import static org.elasticsearch.painless.WriterConstants.DEF_DYNAMIC_LOAD_FIELD_DESC; -import static org.elasticsearch.painless.WriterConstants.DEF_DYNAMIC_STORE_FIELD_DESC; /** * Represents a field load/store or shortcut on a def type. (Internal only.) @@ -57,11 +56,13 @@ final class LDefField extends ALink { @Override void load(final CompilerSettings settings, final Definition definition, final GeneratorAdapter adapter) { - adapter.visitInvokeDynamicInsn(value, DEF_DYNAMIC_LOAD_FIELD_DESC, DEF_BOOTSTRAP_HANDLE, new Object[] { DefBootstrap.LOAD }); + final String desc = Type.getMethodDescriptor(definition.defType.type, definition.defType.type); + adapter.visitInvokeDynamicInsn(value, desc, DEF_BOOTSTRAP_HANDLE, new Object[] { DefBootstrap.LOAD }); } @Override void store(final CompilerSettings settings, final Definition definition, final GeneratorAdapter adapter) { - adapter.visitInvokeDynamicInsn(value, DEF_DYNAMIC_STORE_FIELD_DESC, DEF_BOOTSTRAP_HANDLE, new Object[] { DefBootstrap.STORE }); + final String desc = Type.getMethodDescriptor(definition.voidType.type, definition.defType.type, definition.defType.type); + adapter.visitInvokeDynamicInsn(value, desc, DEF_BOOTSTRAP_HANDLE, new Object[] { DefBootstrap.STORE }); } }