diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/ClassWriter.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/ClassWriter.java new file mode 100644 index 0000000000000..57eb6afbc4edc --- /dev/null +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/ClassWriter.java @@ -0,0 +1,101 @@ +/* + * Licensed to Elasticsearch under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.elasticsearch.painless; + +import org.objectweb.asm.ClassVisitor; +import org.objectweb.asm.Opcodes; +import org.objectweb.asm.Type; +import org.objectweb.asm.commons.Method; +import org.objectweb.asm.util.Printer; +import org.objectweb.asm.util.TraceClassVisitor; + +import java.io.Closeable; +import java.util.BitSet; + +/** + * Manages the top level writers for class and possibly + * clinit if necessary. + */ +public class ClassWriter implements Closeable { + + protected final CompilerSettings compilerSettings; + protected final BitSet statements; + + protected final org.objectweb.asm.ClassWriter classWriter; + protected final ClassVisitor classVisitor; + protected MethodWriter clinitWriter = null; + + public ClassWriter(CompilerSettings compilerSettings, BitSet statements, Printer debugStream, + Class baseClass, int classFrames, int classAccess, String className, String[] classInterfaces) { + + this.compilerSettings = compilerSettings; + this.statements = statements; + + classWriter = new org.objectweb.asm.ClassWriter(classFrames); + ClassVisitor visitor = classWriter; + + if (compilerSettings.isPicky()) { + visitor = new SimpleChecksAdapter(visitor); + } + + if (debugStream != null) { + visitor = new TraceClassVisitor(visitor, debugStream, null); + } + + classVisitor = visitor; + classVisitor.visit(WriterConstants.CLASS_VERSION, classAccess, className, null, + Type.getType(baseClass).getInternalName(), classInterfaces); + } + + public ClassVisitor getClassVisitor() { + return classVisitor; + } + + /** + * Lazy loads the {@link MethodWriter} for clinit, so that if it's not + * necessary the method is never created for the class. + */ + public MethodWriter getClinitWriter() { + if (clinitWriter == null) { + clinitWriter = new MethodWriter(Opcodes.ACC_STATIC, WriterConstants.CLINIT, classVisitor, statements, compilerSettings); + clinitWriter.visitCode(); + } + + return clinitWriter; + } + + public MethodWriter newMethodWriter(int access, Method method) { + return new MethodWriter(access, method, classVisitor, statements, compilerSettings); + } + + @Override + public void close() { + if (clinitWriter != null) { + clinitWriter.returnValue(); + clinitWriter.endMethod(); + } + + classVisitor.visitEnd(); + } + + public byte[] getClassBytes() { + return classWriter.toByteArray(); + } +} diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/antlr/PainlessLexer.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/antlr/PainlessLexer.java index feebacc60687b..d1a7767ce79b0 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/antlr/PainlessLexer.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/antlr/PainlessLexer.java @@ -1,13 +1,17 @@ // ANTLR GENERATED CODE: DO NOT EDIT package org.elasticsearch.painless.antlr; -import org.antlr.v4.runtime.Lexer; + import org.antlr.v4.runtime.CharStream; -import org.antlr.v4.runtime.Token; -import org.antlr.v4.runtime.TokenStream; -import org.antlr.v4.runtime.*; -import org.antlr.v4.runtime.atn.*; +import org.antlr.v4.runtime.Lexer; +import org.antlr.v4.runtime.RuleContext; +import org.antlr.v4.runtime.RuntimeMetaData; +import org.antlr.v4.runtime.Vocabulary; +import org.antlr.v4.runtime.VocabularyImpl; +import org.antlr.v4.runtime.atn.ATN; +import org.antlr.v4.runtime.atn.ATNDeserializer; +import org.antlr.v4.runtime.atn.LexerATNSimulator; +import org.antlr.v4.runtime.atn.PredictionContextCache; import org.antlr.v4.runtime.dfa.DFA; -import org.antlr.v4.runtime.misc.*; @SuppressWarnings({"all", "warnings", "unchecked", "unused", "cast"}) abstract class PainlessLexer extends Lexer { diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/antlr/PainlessParser.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/antlr/PainlessParser.java index c223ab42a94ad..dff6674591ba7 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/antlr/PainlessParser.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/antlr/PainlessParser.java @@ -1,13 +1,25 @@ // ANTLR GENERATED CODE: DO NOT EDIT package org.elasticsearch.painless.antlr; -import org.antlr.v4.runtime.atn.*; + +import org.antlr.v4.runtime.FailedPredicateException; +import org.antlr.v4.runtime.NoViableAltException; +import org.antlr.v4.runtime.Parser; +import org.antlr.v4.runtime.ParserRuleContext; +import org.antlr.v4.runtime.RecognitionException; +import org.antlr.v4.runtime.RuleContext; +import org.antlr.v4.runtime.RuntimeMetaData; +import org.antlr.v4.runtime.TokenStream; +import org.antlr.v4.runtime.Vocabulary; +import org.antlr.v4.runtime.VocabularyImpl; +import org.antlr.v4.runtime.atn.ATN; +import org.antlr.v4.runtime.atn.ATNDeserializer; +import org.antlr.v4.runtime.atn.ParserATNSimulator; +import org.antlr.v4.runtime.atn.PredictionContextCache; import org.antlr.v4.runtime.dfa.DFA; -import org.antlr.v4.runtime.*; -import org.antlr.v4.runtime.misc.*; -import org.antlr.v4.runtime.tree.*; +import org.antlr.v4.runtime.tree.ParseTreeVisitor; +import org.antlr.v4.runtime.tree.TerminalNode; + import java.util.List; -import java.util.Iterator; -import java.util.ArrayList; @SuppressWarnings({"all", "warnings", "unchecked", "unused", "cast"}) class PainlessParser extends Parser { diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/antlr/Walker.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/antlr/Walker.java index ec56bf2845a28..84f44c832d365 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/antlr/Walker.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/antlr/Walker.java @@ -141,6 +141,7 @@ import org.elasticsearch.painless.node.SBlock; import org.elasticsearch.painless.node.SBreak; import org.elasticsearch.painless.node.SCatch; +import org.elasticsearch.painless.node.SClass; import org.elasticsearch.painless.node.SContinue; import org.elasticsearch.painless.node.SDeclBlock; import org.elasticsearch.painless.node.SDeclaration; @@ -152,7 +153,6 @@ import org.elasticsearch.painless.node.SIf; import org.elasticsearch.painless.node.SIfElse; import org.elasticsearch.painless.node.SReturn; -import org.elasticsearch.painless.node.SClass; import org.elasticsearch.painless.node.SThrow; import org.elasticsearch.painless.node.STry; import org.elasticsearch.painless.node.SWhile; diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/ANode.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/ANode.java index 50430c68a1bdf..011c95890dc0a 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/ANode.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/ANode.java @@ -19,6 +19,7 @@ package org.elasticsearch.painless.node; +import org.elasticsearch.painless.ClassWriter; import org.elasticsearch.painless.CompilerSettings; import org.elasticsearch.painless.Globals; import org.elasticsearch.painless.Locals; @@ -75,7 +76,7 @@ public abstract class ANode { /** * Writes ASM based on the data collected during the analysis phase. */ - abstract void write(MethodWriter writer, Globals globals); + abstract void write(ClassWriter classWriter, MethodWriter methodWriter, Globals globals); /** * Create an error with location information pointing to this node. diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/AStoreable.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/AStoreable.java index 824582f5ad30d..7299a14677d9e 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/AStoreable.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/AStoreable.java @@ -19,6 +19,7 @@ package org.elasticsearch.painless.node; +import org.elasticsearch.painless.ClassWriter; import org.elasticsearch.painless.Globals; import org.elasticsearch.painless.Location; import org.elasticsearch.painless.MethodWriter; @@ -91,17 +92,17 @@ abstract class AStoreable extends AExpression { * Called before a storeable node is loaded or stored. Used to load prefixes and * push load/store constants onto the stack if necessary. */ - abstract void setup(MethodWriter writer, Globals globals); + abstract void setup(ClassWriter classWriter, MethodWriter writer, Globals globals); /** * Called to load a storable used for compound assignments. */ - abstract void load(MethodWriter writer, Globals globals); + abstract void load(ClassWriter classWriter, MethodWriter writer, Globals globals); /** * Called to store a storabable to local memory. */ - abstract void store(MethodWriter writer, Globals globals); + abstract void store(ClassWriter classWriter, MethodWriter writer, Globals globals); /** * Writes the opcodes to flip a negative array index (meaning slots from the end of the array) into a 0-based one (meaning slots from diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/EAssignment.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/EAssignment.java index 1d016a4ce9aee..290c38724ae6f 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/EAssignment.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/EAssignment.java @@ -21,6 +21,7 @@ import org.elasticsearch.painless.AnalyzerCaster; +import org.elasticsearch.painless.ClassWriter; import org.elasticsearch.painless.CompilerSettings; import org.elasticsearch.painless.DefBootstrap; import org.elasticsearch.painless.Globals; @@ -250,8 +251,8 @@ private void analyzeSimple(Locals locals) { * also read from. */ @Override - void write(MethodWriter writer, Globals globals) { - writer.writeDebugInfo(location); + void write(ClassWriter classWriter, MethodWriter methodWriter, Globals globals) { + methodWriter.writeDebugInfo(location); // For the case where the assignment represents a String concatenation // we must, depending on the Java version, write a StringBuilder or @@ -261,86 +262,87 @@ void write(MethodWriter writer, Globals globals) { int catElementStackSize = 0; if (cat) { - catElementStackSize = writer.writeNewStrings(); + catElementStackSize = methodWriter.writeNewStrings(); } // Cast the lhs to a storeable to perform the necessary operations to store the rhs. AStoreable lhs = (AStoreable)this.lhs; - lhs.setup(writer, globals); // call the setup method on the lhs to prepare for a load/store operation + lhs.setup(classWriter, methodWriter, globals); // call the setup method on the lhs to prepare for a load/store operation if (cat) { // Handle the case where we are doing a compound assignment // representing a String concatenation. - writer.writeDup(lhs.accessElementCount(), catElementStackSize); // dup the top element and insert it + methodWriter.writeDup(lhs.accessElementCount(), catElementStackSize); // dup the top element and insert it // before concat helper on stack - lhs.load(writer, globals); // read the current lhs's value - writer.writeAppendStrings(lhs.actual); // append the lhs's value using the StringBuilder + lhs.load(classWriter, methodWriter, globals); // read the current lhs's value + methodWriter.writeAppendStrings(lhs.actual); // append the lhs's value using the StringBuilder - rhs.write(writer, globals); // write the bytecode for the rhs + rhs.write(classWriter, methodWriter, globals); // write the bytecode for the rhs if (!(rhs instanceof EBinary) || !((EBinary)rhs).cat) { // check to see if the rhs has already done a concatenation - writer.writeAppendStrings(rhs.actual); // append the rhs's value since it's hasn't already + methodWriter.writeAppendStrings(rhs.actual); // append the rhs's value since it's hasn't already } - writer.writeToStrings(); // put the value for string concat onto the stack - writer.writeCast(back); // if necessary, cast the String to the lhs actual type + methodWriter.writeToStrings(); // put the value for string concat onto the stack + methodWriter.writeCast(back); // if necessary, cast the String to the lhs actual type if (lhs.read) { - writer.writeDup(MethodWriter.getType(lhs.actual).getSize(), lhs.accessElementCount()); // if this lhs is also read + methodWriter.writeDup(MethodWriter.getType(lhs.actual).getSize(), lhs.accessElementCount()); // if this lhs is also read // from dup the value onto the stack } - // store the lhs's value from the stack in its respective variable/field/array - lhs.store(writer, globals); + lhs.store(classWriter, methodWriter, globals); // store the lhs's value from the stack in its respective variable/field/array } else if (operation != null) { // Handle the case where we are doing a compound assignment that // does not represent a String concatenation. - writer.writeDup(lhs.accessElementCount(), 0); // if necessary, dup the previous lhs's value - // to be both loaded from and stored to - lhs.load(writer, globals); // load the current lhs's value + methodWriter.writeDup(lhs.accessElementCount(), 0); // if necessary, dup the previous lhs's value + // to be both loaded from and stored to + lhs.load(classWriter, methodWriter, globals); // load the current lhs's value if (lhs.read && post) { - writer.writeDup(MethodWriter.getType(lhs.actual).getSize(), lhs.accessElementCount()); // dup the value if the lhs is also - // read from and is a post increment + methodWriter.writeDup(MethodWriter.getType(lhs.actual).getSize(), lhs.accessElementCount()); // dup the value if the + // lhs is also + // read from and is a post + // increment } - writer.writeCast(there); // if necessary cast the current lhs's value - // to the promotion type between the lhs and rhs types - rhs.write(writer, globals); // write the bytecode for the rhs + methodWriter.writeCast(there); // if necessary cast the current lhs's value + // to the promotion type between the lhs and rhs types + rhs.write(classWriter, methodWriter, globals); // write the bytecode for the rhs // XXX: fix these types, but first we need def compound assignment tests. // its tricky here as there are possibly explicit casts, too. // write the operation instruction for compound assignment if (promote == def.class) { - writer.writeDynamicBinaryInstruction( + methodWriter.writeDynamicBinaryInstruction( location, promote, def.class, def.class, operation, DefBootstrap.OPERATOR_COMPOUND_ASSIGNMENT); } else { - writer.writeBinaryInstruction(location, promote, operation); + methodWriter.writeBinaryInstruction(location, promote, operation); } - writer.writeCast(back); // if necessary cast the promotion type value back to the lhs's type + methodWriter.writeCast(back); // if necessary cast the promotion type value back to the lhs's type if (lhs.read && !post) { - // dup the value if the lhs is also read from and is not a post increment - writer.writeDup(MethodWriter.getType(lhs.actual).getSize(), lhs.accessElementCount()); + methodWriter.writeDup(MethodWriter.getType(lhs.actual).getSize(), lhs.accessElementCount()); // dup the value if the lhs + // is also + // read from and is not a post + // increment } - // store the lhs's value from the stack in its respective variable/field/array - lhs.store(writer, globals); + lhs.store(classWriter, methodWriter, globals); // store the lhs's value from the stack in its respective variable/field/array } else { // Handle the case for a simple write. - rhs.write(writer, globals); // write the bytecode for the rhs rhs + rhs.write(classWriter, methodWriter, globals); // write the bytecode for the rhs rhs if (lhs.read) { - // dup the value if the lhs is also read from - writer.writeDup(MethodWriter.getType(lhs.actual).getSize(), lhs.accessElementCount()); + methodWriter.writeDup(MethodWriter.getType(lhs.actual).getSize(), lhs.accessElementCount()); // dup the value if the lhs + // is also read from } - // store the lhs's value from the stack in its respective variable/field/array - lhs.store(writer, globals); + lhs.store(classWriter, methodWriter, globals); // store the lhs's value from the stack in its respective variable/field/array } } diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/EBinary.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/EBinary.java index 36bf103936d0d..57c9f713968c6 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/EBinary.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/EBinary.java @@ -20,6 +20,7 @@ package org.elasticsearch.painless.node; import org.elasticsearch.painless.AnalyzerCaster; +import org.elasticsearch.painless.ClassWriter; import org.elasticsearch.painless.CompilerSettings; import org.elasticsearch.painless.DefBootstrap; import org.elasticsearch.painless.Globals; @@ -626,44 +627,44 @@ private void analyzeBWOr(Locals variables) { } @Override - void write(MethodWriter writer, Globals globals) { - writer.writeDebugInfo(location); + void write(ClassWriter classWriter, MethodWriter methodWriter, Globals globals) { + methodWriter.writeDebugInfo(location); if (promote == String.class && operation == Operation.ADD) { if (!cat) { - writer.writeNewStrings(); + methodWriter.writeNewStrings(); } - left.write(writer, globals); + left.write(classWriter, methodWriter, globals); if (!(left instanceof EBinary) || !((EBinary)left).cat) { - writer.writeAppendStrings(left.actual); + methodWriter.writeAppendStrings(left.actual); } - right.write(writer, globals); + right.write(classWriter, methodWriter, globals); if (!(right instanceof EBinary) || !((EBinary)right).cat) { - writer.writeAppendStrings(right.actual); + methodWriter.writeAppendStrings(right.actual); } if (!cat) { - writer.writeToStrings(); + methodWriter.writeToStrings(); } } else if (operation == Operation.FIND || operation == Operation.MATCH) { - right.write(writer, globals); - left.write(writer, globals); - writer.invokeVirtual(org.objectweb.asm.Type.getType(Pattern.class), WriterConstants.PATTERN_MATCHER); + right.write(classWriter, methodWriter, globals); + left.write(classWriter, methodWriter, globals); + methodWriter.invokeVirtual(org.objectweb.asm.Type.getType(Pattern.class), WriterConstants.PATTERN_MATCHER); if (operation == Operation.FIND) { - writer.invokeVirtual(org.objectweb.asm.Type.getType(Matcher.class), WriterConstants.MATCHER_FIND); + methodWriter.invokeVirtual(org.objectweb.asm.Type.getType(Matcher.class), WriterConstants.MATCHER_FIND); } else if (operation == Operation.MATCH) { - writer.invokeVirtual(org.objectweb.asm.Type.getType(Matcher.class), WriterConstants.MATCHER_MATCHES); + methodWriter.invokeVirtual(org.objectweb.asm.Type.getType(Matcher.class), WriterConstants.MATCHER_MATCHES); } else { throw new IllegalStateException("Illegal tree structure."); } } else { - left.write(writer, globals); - right.write(writer, globals); + left.write(classWriter, methodWriter, globals); + right.write(classWriter, methodWriter, globals); if (promote == def.class || (shiftDistance != null && shiftDistance == def.class)) { // def calls adopt the wanted return value. if there was a narrowing cast, @@ -672,9 +673,9 @@ void write(MethodWriter writer, Globals globals) { if (originallyExplicit) { flags |= DefBootstrap.OPERATOR_EXPLICIT_CAST; } - writer.writeDynamicBinaryInstruction(location, actual, left.actual, right.actual, operation, flags); + methodWriter.writeDynamicBinaryInstruction(location, actual, left.actual, right.actual, operation, flags); } else { - writer.writeBinaryInstruction(location, actual, operation); + methodWriter.writeBinaryInstruction(location, actual, operation); } } } diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/EBool.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/EBool.java index 792ffc458acde..283bf62132b4e 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/EBool.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/EBool.java @@ -19,6 +19,7 @@ package org.elasticsearch.painless.node; +import org.elasticsearch.painless.ClassWriter; import org.elasticsearch.painless.CompilerSettings; import org.elasticsearch.painless.Globals; import org.elasticsearch.painless.Locals; @@ -84,37 +85,37 @@ void analyze(Locals locals) { } @Override - void write(MethodWriter writer, Globals globals) { + void write(ClassWriter classWriter, MethodWriter methodWriter, Globals globals) { if (operation == Operation.AND) { Label fals = new Label(); Label end = new Label(); - left.write(writer, globals); - writer.ifZCmp(Opcodes.IFEQ, fals); - right.write(writer, globals); - writer.ifZCmp(Opcodes.IFEQ, fals); + left.write(classWriter, methodWriter, globals); + methodWriter.ifZCmp(Opcodes.IFEQ, fals); + right.write(classWriter, methodWriter, globals); + methodWriter.ifZCmp(Opcodes.IFEQ, fals); - writer.push(true); - writer.goTo(end); - writer.mark(fals); - writer.push(false); - writer.mark(end); + methodWriter.push(true); + methodWriter.goTo(end); + methodWriter.mark(fals); + methodWriter.push(false); + methodWriter.mark(end); } else if (operation == Operation.OR) { Label tru = new Label(); Label fals = new Label(); Label end = new Label(); - left.write(writer, globals); - writer.ifZCmp(Opcodes.IFNE, tru); - right.write(writer, globals); - writer.ifZCmp(Opcodes.IFEQ, fals); - - writer.mark(tru); - writer.push(true); - writer.goTo(end); - writer.mark(fals); - writer.push(false); - writer.mark(end); + left.write(classWriter, methodWriter, globals); + methodWriter.ifZCmp(Opcodes.IFNE, tru); + right.write(classWriter, methodWriter, globals); + methodWriter.ifZCmp(Opcodes.IFEQ, fals); + + methodWriter.mark(tru); + methodWriter.push(true); + methodWriter.goTo(end); + methodWriter.mark(fals); + methodWriter.push(false); + methodWriter.mark(end); } else { throw createError(new IllegalStateException("Illegal tree structure.")); } diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/EBoolean.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/EBoolean.java index 68f297f800c6f..4f7eb820031da 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/EBoolean.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/EBoolean.java @@ -19,6 +19,7 @@ package org.elasticsearch.painless.node; +import org.elasticsearch.painless.ClassWriter; import org.elasticsearch.painless.CompilerSettings; import org.elasticsearch.painless.Globals; import org.elasticsearch.painless.Locals; @@ -58,7 +59,7 @@ void analyze(Locals locals) { } @Override - void write(MethodWriter adapter, Globals globals) { + void write(ClassWriter classWriter, MethodWriter adapter, Globals globals) { throw createError(new IllegalStateException("Illegal tree structure.")); } diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/ECallLocal.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/ECallLocal.java index b16a342434231..900bfce21c9ea 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/ECallLocal.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/ECallLocal.java @@ -19,6 +19,7 @@ package org.elasticsearch.painless.node; +import org.elasticsearch.painless.ClassWriter; import org.elasticsearch.painless.CompilerSettings; import org.elasticsearch.painless.Globals; import org.elasticsearch.painless.Locals; @@ -154,21 +155,21 @@ void analyze(Locals locals) { } @Override - void write(MethodWriter writer, Globals globals) { - writer.writeDebugInfo(location); + void write(ClassWriter classWriter, MethodWriter methodWriter, Globals globals) { + methodWriter.writeDebugInfo(location); if (localMethod != null) { for (AExpression argument : arguments) { - argument.write(writer, globals); + argument.write(classWriter, methodWriter, globals); } - writer.invokeStatic(CLASS_TYPE, new Method(localMethod.name, localMethod.methodType.toMethodDescriptorString())); + methodWriter.invokeStatic(CLASS_TYPE, new Method(localMethod.name, localMethod.methodType.toMethodDescriptorString())); } else if (importedMethod != null) { for (AExpression argument : arguments) { - argument.write(writer, globals); + argument.write(classWriter, methodWriter, globals); } - writer.invokeStatic(Type.getType(importedMethod.targetClass), + methodWriter.invokeStatic(Type.getType(importedMethod.targetClass), new Method(importedMethod.javaMethod.getName(), importedMethod.methodType.toMethodDescriptorString())); } else if (classBinding != null) { String name = globals.addClassBinding(classBinding.javaConstructor.getDeclaringClass()); @@ -177,45 +178,45 @@ void write(MethodWriter writer, Globals globals) { Label nonNull = new Label(); - writer.loadThis(); - writer.getField(CLASS_TYPE, name, type); - writer.ifNonNull(nonNull); - writer.loadThis(); - writer.newInstance(type); - writer.dup(); + methodWriter.loadThis(); + methodWriter.getField(CLASS_TYPE, name, type); + methodWriter.ifNonNull(nonNull); + methodWriter.loadThis(); + methodWriter.newInstance(type); + methodWriter.dup(); if (classBindingOffset == 1) { - writer.loadThis(); + methodWriter.loadThis(); } for (int argument = 0; argument < javaConstructorParameterCount; ++argument) { - arguments.get(argument).write(writer, globals); + arguments.get(argument).write(classWriter, methodWriter, globals); } - writer.invokeConstructor(type, Method.getMethod(classBinding.javaConstructor)); - writer.putField(CLASS_TYPE, name, type); + methodWriter.invokeConstructor(type, Method.getMethod(classBinding.javaConstructor)); + methodWriter.putField(CLASS_TYPE, name, type); - writer.mark(nonNull); - writer.loadThis(); - writer.getField(CLASS_TYPE, name, type); + methodWriter.mark(nonNull); + methodWriter.loadThis(); + methodWriter.getField(CLASS_TYPE, name, type); for (int argument = 0; argument < classBinding.javaMethod.getParameterCount(); ++argument) { - arguments.get(argument + javaConstructorParameterCount).write(writer, globals); + arguments.get(argument + javaConstructorParameterCount).write(classWriter, methodWriter, globals); } - writer.invokeVirtual(type, Method.getMethod(classBinding.javaMethod)); + methodWriter.invokeVirtual(type, Method.getMethod(classBinding.javaMethod)); } else if (instanceBinding != null) { String name = globals.addInstanceBinding(instanceBinding.targetInstance); Type type = Type.getType(instanceBinding.targetInstance.getClass()); - writer.loadThis(); - writer.getStatic(CLASS_TYPE, name, type); + methodWriter.loadThis(); + methodWriter.getStatic(CLASS_TYPE, name, type); for (int argument = 0; argument < instanceBinding.javaMethod.getParameterCount(); ++argument) { - arguments.get(argument).write(writer, globals); + arguments.get(argument).write(classWriter, methodWriter, globals); } - writer.invokeVirtual(type, Method.getMethod(instanceBinding.javaMethod)); + methodWriter.invokeVirtual(type, Method.getMethod(instanceBinding.javaMethod)); } else { throw new IllegalStateException("Illegal tree structure."); } diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/ECapturingFunctionRef.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/ECapturingFunctionRef.java index 8f78442ab37f1..2b2f66980dd9a 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/ECapturingFunctionRef.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/ECapturingFunctionRef.java @@ -19,6 +19,7 @@ package org.elasticsearch.painless.node; +import org.elasticsearch.painless.ClassWriter; import org.elasticsearch.painless.CompilerSettings; import org.elasticsearch.painless.DefBootstrap; import org.elasticsearch.painless.FunctionRef; @@ -87,22 +88,22 @@ void analyze(Locals locals) { } @Override - void write(MethodWriter writer, Globals globals) { - writer.writeDebugInfo(location); + void write(ClassWriter classWriter, MethodWriter methodWriter, Globals globals) { + methodWriter.writeDebugInfo(location); if (defPointer != null) { // dynamic interface: push captured parameter on stack // TODO: don't do this: its just to cutover :) - writer.push((String)null); - writer.visitVarInsn(MethodWriter.getType(captured.clazz).getOpcode(Opcodes.ILOAD), captured.getSlot()); + methodWriter.push((String)null); + methodWriter.visitVarInsn(MethodWriter.getType(captured.clazz).getOpcode(Opcodes.ILOAD), captured.getSlot()); } else if (ref == null) { // typed interface, dynamic implementation - writer.visitVarInsn(MethodWriter.getType(captured.clazz).getOpcode(Opcodes.ILOAD), captured.getSlot()); + methodWriter.visitVarInsn(MethodWriter.getType(captured.clazz).getOpcode(Opcodes.ILOAD), captured.getSlot()); Type methodType = Type.getMethodType(MethodWriter.getType(expected), MethodWriter.getType(captured.clazz)); - writer.invokeDefCall(call, methodType, DefBootstrap.REFERENCE, PainlessLookupUtility.typeToCanonicalTypeName(expected)); + methodWriter.invokeDefCall(call, methodType, DefBootstrap.REFERENCE, PainlessLookupUtility.typeToCanonicalTypeName(expected)); } else { // typed interface, typed implementation - writer.visitVarInsn(MethodWriter.getType(captured.clazz).getOpcode(Opcodes.ILOAD), captured.getSlot()); - writer.invokeLambdaCall(ref); + methodWriter.visitVarInsn(MethodWriter.getType(captured.clazz).getOpcode(Opcodes.ILOAD), captured.getSlot()); + methodWriter.invokeLambdaCall(ref); } } diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/ECast.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/ECast.java index abbc275500488..b88f7a299dce9 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/ECast.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/ECast.java @@ -19,6 +19,7 @@ package org.elasticsearch.painless.node; +import org.elasticsearch.painless.ClassWriter; import org.elasticsearch.painless.CompilerSettings; import org.elasticsearch.painless.Globals; import org.elasticsearch.painless.Locals; @@ -61,10 +62,10 @@ void analyze(Locals locals) { } @Override - void write(MethodWriter writer, Globals globals) { - child.write(writer, globals); - writer.writeDebugInfo(location); - writer.writeCast(cast); + void write(ClassWriter classWriter, MethodWriter methodWriter, Globals globals) { + child.write(classWriter, methodWriter, globals); + methodWriter.writeDebugInfo(location); + methodWriter.writeCast(cast); } @Override diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/EComp.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/EComp.java index 11f94db76edc2..f70da76efea87 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/EComp.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/EComp.java @@ -20,6 +20,7 @@ package org.elasticsearch.painless.node; import org.elasticsearch.painless.AnalyzerCaster; +import org.elasticsearch.painless.ClassWriter; import org.elasticsearch.painless.CompilerSettings; import org.elasticsearch.painless.DefBootstrap; import org.elasticsearch.painless.Globals; @@ -435,13 +436,13 @@ private void analyzeLT(Locals variables) { } @Override - void write(MethodWriter writer, Globals globals) { - writer.writeDebugInfo(location); + void write(ClassWriter classWriter, MethodWriter methodWriter, Globals globals) { + methodWriter.writeDebugInfo(location); - left.write(writer, globals); + left.write(classWriter, methodWriter, globals); if (!right.isNull) { - right.write(writer, globals); + right.write(classWriter, methodWriter, globals); } Label jump = new Label(); @@ -461,18 +462,18 @@ void write(MethodWriter writer, Globals globals) { if (promotedType == void.class || promotedType == byte.class || promotedType == short.class || promotedType == char.class) { throw createError(new IllegalStateException("Illegal tree structure.")); } else if (promotedType == boolean.class) { - if (eq) writer.ifCmp(type, MethodWriter.EQ, jump); - else if (ne) writer.ifCmp(type, MethodWriter.NE, jump); + if (eq) methodWriter.ifCmp(type, MethodWriter.EQ, jump); + else if (ne) methodWriter.ifCmp(type, MethodWriter.NE, jump); else { throw createError(new IllegalStateException("Illegal tree structure.")); } } else if (promotedType == int.class || promotedType == long.class || promotedType == float.class || promotedType == double.class) { - if (eq) writer.ifCmp(type, MethodWriter.EQ, jump); - else if (ne) writer.ifCmp(type, MethodWriter.NE, jump); - else if (lt) writer.ifCmp(type, MethodWriter.LT, jump); - else if (lte) writer.ifCmp(type, MethodWriter.LE, jump); - else if (gt) writer.ifCmp(type, MethodWriter.GT, jump); - else if (gte) writer.ifCmp(type, MethodWriter.GE, jump); + if (eq) methodWriter.ifCmp(type, MethodWriter.EQ, jump); + else if (ne) methodWriter.ifCmp(type, MethodWriter.NE, jump); + else if (lt) methodWriter.ifCmp(type, MethodWriter.LT, jump); + else if (lte) methodWriter.ifCmp(type, MethodWriter.LE, jump); + else if (gt) methodWriter.ifCmp(type, MethodWriter.GT, jump); + else if (gte) methodWriter.ifCmp(type, MethodWriter.GE, jump); else { throw createError(new IllegalStateException("Illegal tree structure.")); } @@ -483,33 +484,33 @@ void write(MethodWriter writer, Globals globals) { if (eq) { if (right.isNull) { - writer.ifNull(jump); + methodWriter.ifNull(jump); } else if (!left.isNull && operation == Operation.EQ) { - writer.invokeDefCall("eq", descriptor, DefBootstrap.BINARY_OPERATOR, DefBootstrap.OPERATOR_ALLOWS_NULL); + methodWriter.invokeDefCall("eq", descriptor, DefBootstrap.BINARY_OPERATOR, DefBootstrap.OPERATOR_ALLOWS_NULL); writejump = false; } else { - writer.ifCmp(type, MethodWriter.EQ, jump); + methodWriter.ifCmp(type, MethodWriter.EQ, jump); } } else if (ne) { if (right.isNull) { - writer.ifNonNull(jump); + methodWriter.ifNonNull(jump); } else if (!left.isNull && operation == Operation.NE) { - writer.invokeDefCall("eq", descriptor, DefBootstrap.BINARY_OPERATOR, DefBootstrap.OPERATOR_ALLOWS_NULL); - writer.ifZCmp(MethodWriter.EQ, jump); + methodWriter.invokeDefCall("eq", descriptor, DefBootstrap.BINARY_OPERATOR, DefBootstrap.OPERATOR_ALLOWS_NULL); + methodWriter.ifZCmp(MethodWriter.EQ, jump); } else { - writer.ifCmp(type, MethodWriter.NE, jump); + methodWriter.ifCmp(type, MethodWriter.NE, jump); } } else if (lt) { - writer.invokeDefCall("lt", descriptor, DefBootstrap.BINARY_OPERATOR, 0); + methodWriter.invokeDefCall("lt", descriptor, DefBootstrap.BINARY_OPERATOR, 0); writejump = false; } else if (lte) { - writer.invokeDefCall("lte", descriptor, DefBootstrap.BINARY_OPERATOR, 0); + methodWriter.invokeDefCall("lte", descriptor, DefBootstrap.BINARY_OPERATOR, 0); writejump = false; } else if (gt) { - writer.invokeDefCall("gt", descriptor, DefBootstrap.BINARY_OPERATOR, 0); + methodWriter.invokeDefCall("gt", descriptor, DefBootstrap.BINARY_OPERATOR, 0); writejump = false; } else if (gte) { - writer.invokeDefCall("gte", descriptor, DefBootstrap.BINARY_OPERATOR, 0); + methodWriter.invokeDefCall("gte", descriptor, DefBootstrap.BINARY_OPERATOR, 0); writejump = false; } else { throw createError(new IllegalStateException("Illegal tree structure.")); @@ -517,21 +518,21 @@ void write(MethodWriter writer, Globals globals) { } else { if (eq) { if (right.isNull) { - writer.ifNull(jump); + methodWriter.ifNull(jump); } else if (operation == Operation.EQ) { - writer.invokeStatic(OBJECTS_TYPE, EQUALS); + methodWriter.invokeStatic(OBJECTS_TYPE, EQUALS); writejump = false; } else { - writer.ifCmp(type, MethodWriter.EQ, jump); + methodWriter.ifCmp(type, MethodWriter.EQ, jump); } } else if (ne) { if (right.isNull) { - writer.ifNonNull(jump); + methodWriter.ifNonNull(jump); } else if (operation == Operation.NE) { - writer.invokeStatic(OBJECTS_TYPE, EQUALS); - writer.ifZCmp(MethodWriter.EQ, jump); + methodWriter.invokeStatic(OBJECTS_TYPE, EQUALS); + methodWriter.ifZCmp(MethodWriter.EQ, jump); } else { - writer.ifCmp(type, MethodWriter.NE, jump); + methodWriter.ifCmp(type, MethodWriter.NE, jump); } } else { throw createError(new IllegalStateException("Illegal tree structure.")); @@ -539,11 +540,11 @@ void write(MethodWriter writer, Globals globals) { } if (writejump) { - writer.push(false); - writer.goTo(end); - writer.mark(jump); - writer.push(true); - writer.mark(end); + methodWriter.push(false); + methodWriter.goTo(end); + methodWriter.mark(jump); + methodWriter.push(true); + methodWriter.mark(end); } } diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/EConditional.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/EConditional.java index ea98f05a1db3b..146ef3806a278 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/EConditional.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/EConditional.java @@ -20,6 +20,7 @@ package org.elasticsearch.painless.node; import org.elasticsearch.painless.AnalyzerCaster; +import org.elasticsearch.painless.ClassWriter; import org.elasticsearch.painless.CompilerSettings; import org.elasticsearch.painless.Globals; import org.elasticsearch.painless.Locals; @@ -96,20 +97,20 @@ void analyze(Locals locals) { } @Override - void write(MethodWriter writer, Globals globals) { - writer.writeDebugInfo(location); + void write(ClassWriter classWriter, MethodWriter methodWriter, Globals globals) { + methodWriter.writeDebugInfo(location); Label fals = new Label(); Label end = new Label(); - condition.write(writer, globals); - writer.ifZCmp(Opcodes.IFEQ, fals); + condition.write(classWriter, methodWriter, globals); + methodWriter.ifZCmp(Opcodes.IFEQ, fals); - left.write(writer, globals); - writer.goTo(end); - writer.mark(fals); - right.write(writer, globals); - writer.mark(end); + left.write(classWriter, methodWriter, globals); + methodWriter.goTo(end); + methodWriter.mark(fals); + right.write(classWriter, methodWriter, globals); + methodWriter.mark(end); } @Override diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/EConstant.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/EConstant.java index bd02845838512..6b9448bfddb8e 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/EConstant.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/EConstant.java @@ -19,6 +19,7 @@ package org.elasticsearch.painless.node; +import org.elasticsearch.painless.ClassWriter; import org.elasticsearch.painless.CompilerSettings; import org.elasticsearch.painless.Globals; import org.elasticsearch.painless.Locals; @@ -75,16 +76,16 @@ void analyze(Locals locals) { } @Override - void write(MethodWriter writer, Globals globals) { - if (actual == String.class) writer.push((String)constant); - else if (actual == double.class) writer.push((double)constant); - else if (actual == float.class) writer.push((float)constant); - else if (actual == long.class) writer.push((long)constant); - else if (actual == int.class) writer.push((int)constant); - else if (actual == char.class) writer.push((char)constant); - else if (actual == short.class) writer.push((short)constant); - else if (actual == byte.class) writer.push((byte)constant); - else if (actual == boolean.class) writer.push((boolean)constant); + void write(ClassWriter classWriter, MethodWriter methodWriter, Globals globals) { + if (actual == String.class) methodWriter.push((String)constant); + else if (actual == double.class) methodWriter.push((double)constant); + else if (actual == float.class) methodWriter.push((float)constant); + else if (actual == long.class) methodWriter.push((long)constant); + else if (actual == int.class) methodWriter.push((int)constant); + else if (actual == char.class) methodWriter.push((char)constant); + else if (actual == short.class) methodWriter.push((short)constant); + else if (actual == byte.class) methodWriter.push((byte)constant); + else if (actual == boolean.class) methodWriter.push((boolean)constant); else { throw createError(new IllegalStateException("Illegal tree structure.")); } diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/EDecimal.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/EDecimal.java index 03e47cc7c2412..65e926345958e 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/EDecimal.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/EDecimal.java @@ -19,6 +19,7 @@ package org.elasticsearch.painless.node; +import org.elasticsearch.painless.ClassWriter; import org.elasticsearch.painless.CompilerSettings; import org.elasticsearch.painless.Globals; import org.elasticsearch.painless.Locals; @@ -79,7 +80,7 @@ void analyze(Locals locals) { } @Override - void write(MethodWriter writer, Globals globals) { + void write(ClassWriter classWriter, MethodWriter methodWriter, Globals globals) { throw createError(new IllegalStateException("Illegal tree structure.")); } diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/EElvis.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/EElvis.java index 7daac4f4a7e3d..15d3b6ac45cda 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/EElvis.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/EElvis.java @@ -20,6 +20,7 @@ package org.elasticsearch.painless.node; import org.elasticsearch.painless.AnalyzerCaster; +import org.elasticsearch.painless.ClassWriter; import org.elasticsearch.painless.CompilerSettings; import org.elasticsearch.painless.Globals; import org.elasticsearch.painless.Locals; @@ -99,17 +100,17 @@ void analyze(Locals locals) { } @Override - void write(MethodWriter writer, Globals globals) { - writer.writeDebugInfo(location); + void write(ClassWriter classWriter, MethodWriter methodWriter, Globals globals) { + methodWriter.writeDebugInfo(location); Label end = new Label(); - lhs.write(writer, globals); - writer.dup(); - writer.ifNonNull(end); - writer.pop(); - rhs.write(writer, globals); - writer.mark(end); + lhs.write(classWriter, methodWriter, globals); + methodWriter.dup(); + methodWriter.ifNonNull(end); + methodWriter.pop(); + rhs.write(classWriter, methodWriter, globals); + methodWriter.mark(end); } @Override diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/EExplicit.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/EExplicit.java index 97779b2e801cd..5aa9dc535dfca 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/EExplicit.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/EExplicit.java @@ -19,6 +19,7 @@ package org.elasticsearch.painless.node; +import org.elasticsearch.painless.ClassWriter; import org.elasticsearch.painless.CompilerSettings; import org.elasticsearch.painless.Globals; import org.elasticsearch.painless.Locals; @@ -68,7 +69,7 @@ void analyze(Locals locals) { } @Override - void write(MethodWriter writer, Globals globals) { + void write(ClassWriter classWriter, MethodWriter methodWriter, Globals globals) { throw createError(new IllegalStateException("Illegal tree structure.")); } diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/EFunctionRef.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/EFunctionRef.java index 03246e186a3a9..22e169f219e7a 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/EFunctionRef.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/EFunctionRef.java @@ -19,6 +19,7 @@ package org.elasticsearch.painless.node; +import org.elasticsearch.painless.ClassWriter; import org.elasticsearch.painless.CompilerSettings; import org.elasticsearch.painless.FunctionRef; import org.elasticsearch.painless.Globals; @@ -71,13 +72,13 @@ void analyze(Locals locals) { } @Override - void write(MethodWriter writer, Globals globals) { + void write(ClassWriter classWriter, MethodWriter methodWriter, Globals globals) { if (ref != null) { - writer.writeDebugInfo(location); - writer.invokeLambdaCall(ref); + methodWriter.writeDebugInfo(location); + methodWriter.invokeLambdaCall(ref); } else { // TODO: don't do this: its just to cutover :) - writer.push((String)null); + methodWriter.push((String)null); } } diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/EInstanceof.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/EInstanceof.java index 810f7caed9b96..ed6125599c676 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/EInstanceof.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/EInstanceof.java @@ -19,6 +19,7 @@ package org.elasticsearch.painless.node; +import org.elasticsearch.painless.ClassWriter; import org.elasticsearch.painless.CompilerSettings; import org.elasticsearch.painless.Globals; import org.elasticsearch.painless.Locals; @@ -87,19 +88,19 @@ void analyze(Locals locals) { } @Override - void write(MethodWriter writer, Globals globals) { + void write(ClassWriter classWriter, MethodWriter methodWriter, Globals globals) { // primitive types if (primitiveExpression) { // run the expression anyway (who knows what it does) - expression.write(writer, globals); + expression.write(classWriter, methodWriter, globals); // discard its result - writer.writePop(MethodWriter.getType(expression.actual).getSize()); + methodWriter.writePop(MethodWriter.getType(expression.actual).getSize()); // push our result: its a primitive so it cannot be null. - writer.push(resolvedType.isAssignableFrom(expressionType)); + methodWriter.push(resolvedType.isAssignableFrom(expressionType)); } else { // ordinary instanceof - expression.write(writer, globals); - writer.instanceOf(org.objectweb.asm.Type.getType(resolvedType)); + expression.write(classWriter, methodWriter, globals); + methodWriter.instanceOf(org.objectweb.asm.Type.getType(resolvedType)); } } diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/ELambda.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/ELambda.java index bd247caf8d56d..dd7007674d22b 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/ELambda.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/ELambda.java @@ -19,6 +19,7 @@ package org.elasticsearch.painless.node; +import org.elasticsearch.painless.ClassWriter; import org.elasticsearch.painless.CompilerSettings; import org.elasticsearch.painless.FunctionRef; import org.elasticsearch.painless.Globals; @@ -196,23 +197,23 @@ void analyze(Locals locals) { } @Override - void write(MethodWriter writer, Globals globals) { - writer.writeDebugInfo(location); + void write(ClassWriter classWriter, MethodWriter methodWriter, Globals globals) { + methodWriter.writeDebugInfo(location); if (ref != null) { - writer.writeDebugInfo(location); + methodWriter.writeDebugInfo(location); // load captures for (Variable capture : captures) { - writer.visitVarInsn(MethodWriter.getType(capture.clazz).getOpcode(Opcodes.ILOAD), capture.getSlot()); + methodWriter.visitVarInsn(MethodWriter.getType(capture.clazz).getOpcode(Opcodes.ILOAD), capture.getSlot()); } - writer.invokeLambdaCall(ref); + methodWriter.invokeLambdaCall(ref); } else { // placeholder - writer.push((String)null); + methodWriter.push((String)null); // load captures for (Variable capture : captures) { - writer.visitVarInsn(MethodWriter.getType(capture.clazz).getOpcode(Opcodes.ILOAD), capture.getSlot()); + methodWriter.visitVarInsn(MethodWriter.getType(capture.clazz).getOpcode(Opcodes.ILOAD), capture.getSlot()); } } diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/EListInit.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/EListInit.java index 0ccdbdc75861b..6e8a660f65c16 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/EListInit.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/EListInit.java @@ -19,6 +19,7 @@ package org.elasticsearch.painless.node; +import org.elasticsearch.painless.ClassWriter; import org.elasticsearch.painless.CompilerSettings; import org.elasticsearch.painless.Globals; import org.elasticsearch.painless.Locals; @@ -97,19 +98,19 @@ void analyze(Locals locals) { } @Override - void write(MethodWriter writer, Globals globals) { - writer.writeDebugInfo(location); + void write(ClassWriter classWriter, MethodWriter methodWriter, Globals globals) { + methodWriter.writeDebugInfo(location); - writer.newInstance(MethodWriter.getType(actual)); - writer.dup(); - writer.invokeConstructor( + methodWriter.newInstance(MethodWriter.getType(actual)); + methodWriter.dup(); + methodWriter.invokeConstructor( Type.getType(constructor.javaConstructor.getDeclaringClass()), Method.getMethod(constructor.javaConstructor)); for (AExpression value : values) { - writer.dup(); - value.write(writer, globals); - writer.invokeMethodCall(method); - writer.pop(); + methodWriter.dup(); + value.write(classWriter, methodWriter, globals); + methodWriter.invokeMethodCall(method); + methodWriter.pop(); } } diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/EMapInit.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/EMapInit.java index 92c215974d374..d54e0c54d654e 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/EMapInit.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/EMapInit.java @@ -19,6 +19,7 @@ package org.elasticsearch.painless.node; +import org.elasticsearch.painless.ClassWriter; import org.elasticsearch.painless.CompilerSettings; import org.elasticsearch.painless.Globals; import org.elasticsearch.painless.Locals; @@ -120,23 +121,23 @@ void analyze(Locals locals) { } @Override - void write(MethodWriter writer, Globals globals) { - writer.writeDebugInfo(location); + void write(ClassWriter classWriter, MethodWriter methodWriter, Globals globals) { + methodWriter.writeDebugInfo(location); - writer.newInstance(MethodWriter.getType(actual)); - writer.dup(); - writer.invokeConstructor( + methodWriter.newInstance(MethodWriter.getType(actual)); + methodWriter.dup(); + methodWriter.invokeConstructor( Type.getType(constructor.javaConstructor.getDeclaringClass()), Method.getMethod(constructor.javaConstructor)); for (int index = 0; index < keys.size(); ++index) { AExpression key = keys.get(index); AExpression value = values.get(index); - writer.dup(); - key.write(writer, globals); - value.write(writer, globals); - writer.invokeMethodCall(method); - writer.pop(); + methodWriter.dup(); + key.write(classWriter, methodWriter, globals); + value.write(classWriter, methodWriter, globals); + methodWriter.invokeMethodCall(method); + methodWriter.pop(); } } diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/ENewArray.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/ENewArray.java index 418f8f91e9346..f568b09f9de58 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/ENewArray.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/ENewArray.java @@ -19,6 +19,7 @@ package org.elasticsearch.painless.node; +import org.elasticsearch.painless.ClassWriter; import org.elasticsearch.painless.CompilerSettings; import org.elasticsearch.painless.Globals; import org.elasticsearch.painless.Locals; @@ -85,30 +86,30 @@ void analyze(Locals locals) { } @Override - void write(MethodWriter writer, Globals globals) { - writer.writeDebugInfo(location); + void write(ClassWriter classWriter, MethodWriter methodWriter, Globals globals) { + methodWriter.writeDebugInfo(location); if (initialize) { - writer.push(arguments.size()); - writer.newArray(MethodWriter.getType(actual.getComponentType())); + methodWriter.push(arguments.size()); + methodWriter.newArray(MethodWriter.getType(actual.getComponentType())); for (int index = 0; index < arguments.size(); ++index) { AExpression argument = arguments.get(index); - writer.dup(); - writer.push(index); - argument.write(writer, globals); - writer.arrayStore(MethodWriter.getType(actual.getComponentType())); + methodWriter.dup(); + methodWriter.push(index); + argument.write(classWriter, methodWriter, globals); + methodWriter.arrayStore(MethodWriter.getType(actual.getComponentType())); } } else { for (AExpression argument : arguments) { - argument.write(writer, globals); + argument.write(classWriter, methodWriter, globals); } if (arguments.size() > 1) { - writer.visitMultiANewArrayInsn(MethodWriter.getType(actual).getDescriptor(), arguments.size()); + methodWriter.visitMultiANewArrayInsn(MethodWriter.getType(actual).getDescriptor(), arguments.size()); } else { - writer.newArray(MethodWriter.getType(actual.getComponentType())); + methodWriter.newArray(MethodWriter.getType(actual.getComponentType())); } } } diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/ENewArrayFunctionRef.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/ENewArrayFunctionRef.java index 39a4b9eadd031..00dc976d67eef 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/ENewArrayFunctionRef.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/ENewArrayFunctionRef.java @@ -19,6 +19,7 @@ package org.elasticsearch.painless.node; +import org.elasticsearch.painless.ClassWriter; import org.elasticsearch.painless.CompilerSettings; import org.elasticsearch.painless.FunctionRef; import org.elasticsearch.painless.Globals; @@ -85,13 +86,13 @@ void analyze(Locals locals) { } @Override - void write(MethodWriter writer, Globals globals) { + void write(ClassWriter classWriter, MethodWriter methodWriter, Globals globals) { if (ref != null) { - writer.writeDebugInfo(location); - writer.invokeLambdaCall(ref); + methodWriter.writeDebugInfo(location); + methodWriter.invokeLambdaCall(ref); } else { // push a null instruction as a placeholder for future lambda instructions - writer.push((String)null); + methodWriter.push((String)null); } globals.addSyntheticMethod(function); diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/ENewObj.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/ENewObj.java index fcca44a457dda..21efb13df66c6 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/ENewObj.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/ENewObj.java @@ -19,6 +19,7 @@ package org.elasticsearch.painless.node; +import org.elasticsearch.painless.ClassWriter; import org.elasticsearch.painless.CompilerSettings; import org.elasticsearch.painless.Globals; import org.elasticsearch.painless.Locals; @@ -103,20 +104,20 @@ void analyze(Locals locals) { } @Override - void write(MethodWriter writer, Globals globals) { - writer.writeDebugInfo(location); + void write(ClassWriter classWriter, MethodWriter methodWriter, Globals globals) { + methodWriter.writeDebugInfo(location); - writer.newInstance(MethodWriter.getType(actual)); + methodWriter.newInstance(MethodWriter.getType(actual)); if (read) { - writer.dup(); + methodWriter.dup(); } for (AExpression argument : arguments) { - argument.write(writer, globals); + argument.write(classWriter, methodWriter, globals); } - writer.invokeConstructor( + methodWriter.invokeConstructor( Type.getType(constructor.javaConstructor.getDeclaringClass()), Method.getMethod(constructor.javaConstructor)); } diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/ENull.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/ENull.java index 46836c179fc96..8728c6ce049ba 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/ENull.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/ENull.java @@ -19,6 +19,7 @@ package org.elasticsearch.painless.node; +import org.elasticsearch.painless.ClassWriter; import org.elasticsearch.painless.CompilerSettings; import org.elasticsearch.painless.Globals; import org.elasticsearch.painless.Locals; @@ -69,8 +70,8 @@ void analyze(Locals locals) { } @Override - void write(MethodWriter writer, Globals globals) { - writer.visitInsn(Opcodes.ACONST_NULL); + void write(ClassWriter classWriter, MethodWriter methodWriter, Globals globals) { + methodWriter.visitInsn(Opcodes.ACONST_NULL); } @Override diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/ENumeric.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/ENumeric.java index 59f28ccb437c9..91474149adb0f 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/ENumeric.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/ENumeric.java @@ -19,6 +19,7 @@ package org.elasticsearch.painless.node; +import org.elasticsearch.painless.ClassWriter; import org.elasticsearch.painless.CompilerSettings; import org.elasticsearch.painless.Globals; import org.elasticsearch.painless.Locals; @@ -121,7 +122,7 @@ void analyze(Locals locals) { } @Override - void write(MethodWriter writer, Globals globals) { + void write(ClassWriter classWriter, MethodWriter methodWriter, Globals globals) { throw createError(new IllegalStateException("Illegal tree structure.")); } diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/ERegex.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/ERegex.java index 106549c1c1373..020f80b4258f1 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/ERegex.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/ERegex.java @@ -19,6 +19,7 @@ package org.elasticsearch.painless.node; +import org.elasticsearch.painless.ClassWriter; import org.elasticsearch.painless.CompilerSettings; import org.elasticsearch.painless.Constant; import org.elasticsearch.painless.Globals; @@ -91,10 +92,10 @@ void analyze(Locals locals) { } @Override - void write(MethodWriter writer, Globals globals) { - writer.writeDebugInfo(location); + void write(ClassWriter classWriter, MethodWriter methodWriter, Globals globals) { + methodWriter.writeDebugInfo(location); - writer.getStatic(WriterConstants.CLASS_TYPE, constant.name, org.objectweb.asm.Type.getType(Pattern.class)); + methodWriter.getStatic(WriterConstants.CLASS_TYPE, constant.name, org.objectweb.asm.Type.getType(Pattern.class)); globals.addConstantInitializer(constant); } diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/EStatic.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/EStatic.java index 7214d0c7ed6fb..f9220a2f7d508 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/EStatic.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/EStatic.java @@ -19,6 +19,7 @@ package org.elasticsearch.painless.node; +import org.elasticsearch.painless.ClassWriter; import org.elasticsearch.painless.CompilerSettings; import org.elasticsearch.painless.Globals; import org.elasticsearch.painless.Locals; @@ -61,7 +62,7 @@ void analyze(Locals locals) { } @Override - void write(MethodWriter writer, Globals globals) { + void write(ClassWriter classWriter, MethodWriter methodWriter, Globals globals) { // Do nothing. } diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/EString.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/EString.java index 1adf49667454f..9f6908db953e9 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/EString.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/EString.java @@ -19,6 +19,7 @@ package org.elasticsearch.painless.node; +import org.elasticsearch.painless.ClassWriter; import org.elasticsearch.painless.CompilerSettings; import org.elasticsearch.painless.Globals; import org.elasticsearch.painless.Locals; @@ -59,7 +60,7 @@ void analyze(Locals locals) { } @Override - void write(MethodWriter writer, Globals globals) { + void write(ClassWriter classWriter, MethodWriter methodWriter, Globals globals) { throw new IllegalStateException("Illegal tree structure."); } diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/EUnary.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/EUnary.java index f713082ba5ed9..e8c742f6e6f1a 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/EUnary.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/EUnary.java @@ -20,6 +20,7 @@ package org.elasticsearch.painless.node; import org.elasticsearch.painless.AnalyzerCaster; +import org.elasticsearch.painless.ClassWriter; import org.elasticsearch.painless.CompilerSettings; import org.elasticsearch.painless.DefBootstrap; import org.elasticsearch.painless.Globals; @@ -192,23 +193,23 @@ void analyzerSub(Locals variables) { } @Override - void write(MethodWriter writer, Globals globals) { - writer.writeDebugInfo(location); + void write(ClassWriter classWriter, MethodWriter methodWriter, Globals globals) { + methodWriter.writeDebugInfo(location); if (operation == Operation.NOT) { Label fals = new Label(); Label end = new Label(); - child.write(writer, globals); - writer.ifZCmp(Opcodes.IFEQ, fals); + child.write(classWriter, methodWriter, globals); + methodWriter.ifZCmp(Opcodes.IFEQ, fals); - writer.push(false); - writer.goTo(end); - writer.mark(fals); - writer.push(true); - writer.mark(end); + methodWriter.push(false); + methodWriter.goTo(end); + methodWriter.mark(fals); + methodWriter.push(true); + methodWriter.mark(end); } else { - child.write(writer, globals); + child.write(classWriter, methodWriter, globals); // Def calls adopt the wanted return value. If there was a narrowing cast, // we need to flag that so that it's done at runtime. @@ -224,29 +225,29 @@ void write(MethodWriter writer, Globals globals) { if (operation == Operation.BWNOT) { if (promote == def.class) { org.objectweb.asm.Type descriptor = org.objectweb.asm.Type.getMethodType(actualType, childType); - writer.invokeDefCall("not", descriptor, DefBootstrap.UNARY_OPERATOR, defFlags); + methodWriter.invokeDefCall("not", descriptor, DefBootstrap.UNARY_OPERATOR, defFlags); } else { if (promote == int.class) { - writer.push(-1); + methodWriter.push(-1); } else if (promote == long.class) { - writer.push(-1L); + methodWriter.push(-1L); } else { throw createError(new IllegalStateException("Illegal tree structure.")); } - writer.math(MethodWriter.XOR, actualType); + methodWriter.math(MethodWriter.XOR, actualType); } } else if (operation == Operation.SUB) { if (promote == def.class) { org.objectweb.asm.Type descriptor = org.objectweb.asm.Type.getMethodType(actualType, childType); - writer.invokeDefCall("neg", descriptor, DefBootstrap.UNARY_OPERATOR, defFlags); + methodWriter.invokeDefCall("neg", descriptor, DefBootstrap.UNARY_OPERATOR, defFlags); } else { - writer.math(MethodWriter.NEG, actualType); + methodWriter.math(MethodWriter.NEG, actualType); } } else if (operation == Operation.ADD) { if (promote == def.class) { org.objectweb.asm.Type descriptor = org.objectweb.asm.Type.getMethodType(actualType, childType); - writer.invokeDefCall("plus", descriptor, DefBootstrap.UNARY_OPERATOR, defFlags); + methodWriter.invokeDefCall("plus", descriptor, DefBootstrap.UNARY_OPERATOR, defFlags); } } else { throw createError(new IllegalStateException("Illegal tree structure.")); diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/EVariable.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/EVariable.java index 734e1e9c5ea56..46eea554a37e8 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/EVariable.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/EVariable.java @@ -19,6 +19,7 @@ package org.elasticsearch.painless.node; +import org.elasticsearch.painless.ClassWriter; import org.elasticsearch.painless.CompilerSettings; import org.elasticsearch.painless.Globals; import org.elasticsearch.painless.Locals; @@ -67,8 +68,8 @@ void analyze(Locals locals) { } @Override - void write(MethodWriter writer, Globals globals) { - writer.visitVarInsn(MethodWriter.getType(actual).getOpcode(Opcodes.ILOAD), variable.getSlot()); + void write(ClassWriter classWriter, MethodWriter methodWriter, Globals globals) { + methodWriter.visitVarInsn(MethodWriter.getType(actual).getOpcode(Opcodes.ILOAD), variable.getSlot()); } @Override @@ -87,18 +88,18 @@ void updateActual(Class actual) { } @Override - void setup(MethodWriter writer, Globals globals) { + void setup(ClassWriter classWriter, MethodWriter methodWriter, Globals globals) { // Do nothing. } @Override - void load(MethodWriter writer, Globals globals) { - writer.visitVarInsn(MethodWriter.getType(actual).getOpcode(Opcodes.ILOAD), variable.getSlot()); + void load(ClassWriter classWriter, MethodWriter methodWriter, Globals globals) { + methodWriter.visitVarInsn(MethodWriter.getType(actual).getOpcode(Opcodes.ILOAD), variable.getSlot()); } @Override - void store(MethodWriter writer, Globals globals) { - writer.visitVarInsn(MethodWriter.getType(actual).getOpcode(Opcodes.ISTORE), variable.getSlot()); + void store(ClassWriter classWriter, MethodWriter methodWriter, Globals globals) { + methodWriter.visitVarInsn(MethodWriter.getType(actual).getOpcode(Opcodes.ISTORE), variable.getSlot()); } @Override diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/PBrace.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/PBrace.java index 65d4b87ab58c2..1f48be47c2783 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/PBrace.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/PBrace.java @@ -19,6 +19,7 @@ package org.elasticsearch.painless.node; +import org.elasticsearch.painless.ClassWriter; import org.elasticsearch.painless.CompilerSettings; import org.elasticsearch.painless.Globals; import org.elasticsearch.painless.Locals; @@ -87,9 +88,9 @@ void analyze(Locals locals) { } @Override - void write(MethodWriter writer, Globals globals) { - prefix.write(writer, globals); - sub.write(writer, globals); + void write(ClassWriter classWriter, MethodWriter methodWriter, Globals globals) { + prefix.write(classWriter, methodWriter, globals); + sub.write(classWriter, methodWriter, globals); } @Override @@ -109,19 +110,19 @@ int accessElementCount() { } @Override - void setup(MethodWriter writer, Globals globals) { - prefix.write(writer, globals); - sub.setup(writer, globals); + void setup(ClassWriter classWriter, MethodWriter methodWriter, Globals globals) { + prefix.write(classWriter, methodWriter, globals); + sub.setup(classWriter, methodWriter, globals); } @Override - void load(MethodWriter writer, Globals globals) { - sub.load(writer, globals); + void load(ClassWriter classWriter, MethodWriter methodWriter, Globals globals) { + sub.load(classWriter, methodWriter, globals); } @Override - void store(MethodWriter writer, Globals globals) { - sub.store(writer, globals); + void store(ClassWriter classWriter, MethodWriter methodWriter, Globals globals) { + sub.store(classWriter, methodWriter, globals); } @Override diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/PCallInvoke.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/PCallInvoke.java index 4103b6165ac36..16157a4b52e4b 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/PCallInvoke.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/PCallInvoke.java @@ -19,6 +19,7 @@ package org.elasticsearch.painless.node; +import org.elasticsearch.painless.ClassWriter; import org.elasticsearch.painless.CompilerSettings; import org.elasticsearch.painless.Globals; import org.elasticsearch.painless.Locals; @@ -103,9 +104,9 @@ void analyze(Locals locals) { } @Override - void write(MethodWriter writer, Globals globals) { - prefix.write(writer, globals); - sub.write(writer, globals); + void write(ClassWriter classWriter, MethodWriter methodWriter, Globals globals) { + prefix.write(classWriter, methodWriter, globals); + sub.write(classWriter, methodWriter, globals); } @Override diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/PField.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/PField.java index 9a00421c61655..261c9f7168f75 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/PField.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/PField.java @@ -19,6 +19,7 @@ package org.elasticsearch.painless.node; +import org.elasticsearch.painless.ClassWriter; import org.elasticsearch.painless.CompilerSettings; import org.elasticsearch.painless.Globals; import org.elasticsearch.painless.Locals; @@ -128,9 +129,9 @@ void analyze(Locals locals) { } @Override - void write(MethodWriter writer, Globals globals) { - prefix.write(writer, globals); - sub.write(writer, globals); + void write(ClassWriter classWriter, MethodWriter methodWriter, Globals globals) { + prefix.write(classWriter, methodWriter, globals); + sub.write(classWriter, methodWriter, globals); } @Override @@ -150,19 +151,19 @@ int accessElementCount() { } @Override - void setup(MethodWriter writer, Globals globals) { - prefix.write(writer, globals); - sub.setup(writer, globals); + void setup(ClassWriter classWriter, MethodWriter methodWriter, Globals globals) { + prefix.write(classWriter, methodWriter, globals); + sub.setup(classWriter, methodWriter, globals); } @Override - void load(MethodWriter writer, Globals globals) { - sub.load(writer, globals); + void load(ClassWriter classWriter, MethodWriter methodWriter, Globals globals) { + sub.load(classWriter, methodWriter, globals); } @Override - void store(MethodWriter writer, Globals globals) { - sub.store(writer, globals); + void store(ClassWriter classWriter, MethodWriter methodWriter, Globals globals) { + sub.store(classWriter, methodWriter, globals); } @Override diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/PSubArrayLength.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/PSubArrayLength.java index 83464f45a253a..43e4eea26e1e5 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/PSubArrayLength.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/PSubArrayLength.java @@ -19,6 +19,7 @@ package org.elasticsearch.painless.node; +import org.elasticsearch.painless.ClassWriter; import org.elasticsearch.painless.CompilerSettings; import org.elasticsearch.painless.Globals; import org.elasticsearch.painless.Locals; @@ -67,9 +68,9 @@ void analyze(Locals locals) { } @Override - void write(MethodWriter writer, Globals globals) { - writer.writeDebugInfo(location); - writer.arrayLength(); + void write(ClassWriter classWriter, MethodWriter methodWriter, Globals globals) { + methodWriter.writeDebugInfo(location); + methodWriter.arrayLength(); } @Override @@ -88,17 +89,17 @@ void updateActual(Class actual) { } @Override - void setup(MethodWriter writer, Globals globals) { + void setup(ClassWriter classWriter, MethodWriter methodWriter, Globals globals) { throw new IllegalStateException("Illegal tree structure."); } @Override - void load(MethodWriter writer, Globals globals) { + void load(ClassWriter classWriter, MethodWriter methodWriter, Globals globals) { throw new IllegalStateException("Illegal tree structure."); } @Override - void store(MethodWriter writer, Globals globals) { + void store(ClassWriter classWriter, MethodWriter methodWriter, Globals globals) { throw new IllegalStateException("Illegal tree structure."); } diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/PSubBrace.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/PSubBrace.java index 79c28168ab70c..fb858e848a33f 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/PSubBrace.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/PSubBrace.java @@ -19,6 +19,7 @@ package org.elasticsearch.painless.node; +import org.elasticsearch.painless.ClassWriter; import org.elasticsearch.painless.CompilerSettings; import org.elasticsearch.painless.Globals; import org.elasticsearch.painless.Locals; @@ -63,9 +64,9 @@ void analyze(Locals locals) { } @Override - void write(MethodWriter writer, Globals globals) { - setup(writer, globals); - load(writer, globals); + void write(ClassWriter classWriter, MethodWriter methodWriter, Globals globals) { + setup(classWriter, methodWriter, globals); + load(classWriter, methodWriter, globals); } @Override @@ -84,21 +85,21 @@ void updateActual(Class actual) { } @Override - void setup(MethodWriter writer, Globals globals) { - index.write(writer, globals); - writeIndexFlip(writer, MethodWriter::arrayLength); + void setup(ClassWriter classWriter, MethodWriter methodWriter, Globals globals) { + index.write(classWriter, methodWriter, globals); + writeIndexFlip(methodWriter, MethodWriter::arrayLength); } @Override - void load(MethodWriter writer, Globals globals) { - writer.writeDebugInfo(location); - writer.arrayLoad(MethodWriter.getType(actual)); + void load(ClassWriter classWriter, MethodWriter methodWriter, Globals globals) { + methodWriter.writeDebugInfo(location); + methodWriter.arrayLoad(MethodWriter.getType(actual)); } @Override - void store(MethodWriter writer, Globals globals) { - writer.writeDebugInfo(location); - writer.arrayStore(MethodWriter.getType(actual)); + void store(ClassWriter classWriter, MethodWriter methodWriter, Globals globals) { + methodWriter.writeDebugInfo(location); + methodWriter.arrayStore(MethodWriter.getType(actual)); } @Override diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/PSubCallInvoke.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/PSubCallInvoke.java index d5fd2849aba87..f168d4cdd4363 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/PSubCallInvoke.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/PSubCallInvoke.java @@ -19,6 +19,7 @@ package org.elasticsearch.painless.node; +import org.elasticsearch.painless.ClassWriter; import org.elasticsearch.painless.CompilerSettings; import org.elasticsearch.painless.Globals; import org.elasticsearch.painless.Locals; @@ -73,18 +74,18 @@ void analyze(Locals locals) { } @Override - void write(MethodWriter writer, Globals globals) { - writer.writeDebugInfo(location); + void write(ClassWriter classWriter, MethodWriter methodWriter, Globals globals) { + methodWriter.writeDebugInfo(location); if (box.isPrimitive()) { - writer.box(MethodWriter.getType(box)); + methodWriter.box(MethodWriter.getType(box)); } for (AExpression argument : arguments) { - argument.write(writer, globals); + argument.write(classWriter, methodWriter, globals); } - writer.invokeMethodCall(method); + methodWriter.invokeMethodCall(method); } @Override diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/PSubDefArray.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/PSubDefArray.java index 4dec674f22ee7..283abf8a43fd4 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/PSubDefArray.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/PSubDefArray.java @@ -19,6 +19,7 @@ package org.elasticsearch.painless.node; +import org.elasticsearch.painless.ClassWriter; import org.elasticsearch.painless.CompilerSettings; import org.elasticsearch.painless.DefBootstrap; import org.elasticsearch.painless.Globals; @@ -65,9 +66,9 @@ void analyze(Locals locals) { } @Override - void write(MethodWriter writer, Globals globals) { - setup(writer, globals); - load(writer, globals); + void write(ClassWriter classWriter, MethodWriter methodWriter, Globals globals) { + setup(classWriter, methodWriter, globals); + load(classWriter, methodWriter, globals); } @Override @@ -86,32 +87,31 @@ void updateActual(Class actual) { } @Override - void setup(MethodWriter writer, Globals globals) { - // Current stack: def - writer.dup(); // def, def - index.write(writer, globals); // def, def, unnormalized_index + void setup(ClassWriter classWriter, MethodWriter methodWriter, Globals globals) { + methodWriter.dup(); + index.write(classWriter, methodWriter, globals); Type methodType = Type.getMethodType( MethodWriter.getType(index.actual), Type.getType(Object.class), MethodWriter.getType(index.actual)); - writer.invokeDefCall("normalizeIndex", methodType, DefBootstrap.INDEX_NORMALIZE); // def, normalized_index + methodWriter.invokeDefCall("normalizeIndex", methodType, DefBootstrap.INDEX_NORMALIZE); } @Override - void load(MethodWriter writer, Globals globals) { - writer.writeDebugInfo(location); + void load(ClassWriter classWriter, MethodWriter methodWriter, Globals globals) { + methodWriter.writeDebugInfo(location); Type methodType = Type.getMethodType(MethodWriter.getType(actual), Type.getType(Object.class), MethodWriter.getType(index.actual)); - writer.invokeDefCall("arrayLoad", methodType, DefBootstrap.ARRAY_LOAD); + methodWriter.invokeDefCall("arrayLoad", methodType, DefBootstrap.ARRAY_LOAD); } @Override - void store(MethodWriter writer, Globals globals) { - writer.writeDebugInfo(location); + void store(ClassWriter classWriter, MethodWriter methodWriter, Globals globals) { + methodWriter.writeDebugInfo(location); Type methodType = Type.getMethodType( Type.getType(void.class), Type.getType(Object.class), MethodWriter.getType(index.actual), MethodWriter.getType(actual)); - writer.invokeDefCall("arrayStore", methodType, DefBootstrap.ARRAY_STORE); + methodWriter.invokeDefCall("arrayStore", methodType, DefBootstrap.ARRAY_STORE); } @Override diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/PSubDefCall.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/PSubDefCall.java index ff5bfe7dd3fcd..19c452e724db0 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/PSubDefCall.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/PSubDefCall.java @@ -19,6 +19,7 @@ package org.elasticsearch.painless.node; +import org.elasticsearch.painless.ClassWriter; import org.elasticsearch.painless.CompilerSettings; import org.elasticsearch.painless.DefBootstrap; import org.elasticsearch.painless.Globals; @@ -96,8 +97,8 @@ void analyze(Locals locals) { } @Override - void write(MethodWriter writer, Globals globals) { - writer.writeDebugInfo(location); + void write(ClassWriter classWriter, MethodWriter methodWriter, Globals globals) { + methodWriter.writeDebugInfo(location); List parameterTypes = new ArrayList<>(); @@ -113,7 +114,7 @@ void write(MethodWriter writer, Globals globals) { Collections.addAll(parameterTypes, lambda.getCaptures()); } - argument.write(writer, globals); + argument.write(classWriter, methodWriter, globals); } // create method type from return value and arguments @@ -122,7 +123,7 @@ void write(MethodWriter writer, Globals globals) { List args = new ArrayList<>(); args.add(recipe.toString()); args.addAll(pointers); - writer.invokeDefCall(name, methodType, DefBootstrap.METHOD_CALL, args.toArray()); + methodWriter.invokeDefCall(name, methodType, DefBootstrap.METHOD_CALL, args.toArray()); } @Override diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/PSubDefField.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/PSubDefField.java index b9c971570eda9..5f86a8ec1a7a1 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/PSubDefField.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/PSubDefField.java @@ -19,6 +19,7 @@ package org.elasticsearch.painless.node; +import org.elasticsearch.painless.ClassWriter; import org.elasticsearch.painless.CompilerSettings; import org.elasticsearch.painless.DefBootstrap; import org.elasticsearch.painless.Globals; @@ -61,12 +62,12 @@ void analyze(Locals locals) { } @Override - void write(MethodWriter writer, Globals globals) { - writer.writeDebugInfo(location); + void write(ClassWriter classWriter, MethodWriter methodWriter, Globals globals) { + methodWriter.writeDebugInfo(location); org.objectweb.asm.Type methodType = org.objectweb.asm.Type.getMethodType(MethodWriter.getType(actual), org.objectweb.asm.Type.getType(Object.class)); - writer.invokeDefCall(value, methodType, DefBootstrap.LOAD); + methodWriter.invokeDefCall(value, methodType, DefBootstrap.LOAD); } @Override @@ -85,26 +86,26 @@ void updateActual(Class actual) { } @Override - void setup(MethodWriter writer, Globals globals) { + void setup(ClassWriter classWriter, MethodWriter methodWriter, Globals globals) { // Do nothing. } @Override - void load(MethodWriter writer, Globals globals) { - writer.writeDebugInfo(location); + void load(ClassWriter classWriter, MethodWriter methodWriter, Globals globals) { + methodWriter.writeDebugInfo(location); org.objectweb.asm.Type methodType = org.objectweb.asm.Type.getMethodType(MethodWriter.getType(actual), org.objectweb.asm.Type.getType(Object.class)); - writer.invokeDefCall(value, methodType, DefBootstrap.LOAD); + methodWriter.invokeDefCall(value, methodType, DefBootstrap.LOAD); } @Override - void store(MethodWriter writer, Globals globals) { - writer.writeDebugInfo(location); + void store(ClassWriter classWriter, MethodWriter methodWriter, Globals globals) { + methodWriter.writeDebugInfo(location); org.objectweb.asm.Type methodType = org.objectweb.asm.Type.getMethodType( org.objectweb.asm.Type.getType(void.class), org.objectweb.asm.Type.getType(Object.class), MethodWriter.getType(actual)); - writer.invokeDefCall(value, methodType, DefBootstrap.STORE); + methodWriter.invokeDefCall(value, methodType, DefBootstrap.STORE); } @Override diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/PSubField.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/PSubField.java index c1d5b45d76c0a..74986cabfb966 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/PSubField.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/PSubField.java @@ -19,6 +19,7 @@ package org.elasticsearch.painless.node; +import org.elasticsearch.painless.ClassWriter; import org.elasticsearch.painless.CompilerSettings; import org.elasticsearch.painless.Globals; import org.elasticsearch.painless.Locals; @@ -66,14 +67,14 @@ void analyze(Locals locals) { } @Override - void write(MethodWriter writer, Globals globals) { - writer.writeDebugInfo(location); + void write(ClassWriter classWriter, MethodWriter methodWriter, Globals globals) { + methodWriter.writeDebugInfo(location); if (java.lang.reflect.Modifier.isStatic(field.javaField.getModifiers())) { - writer.getStatic(Type.getType( + methodWriter.getStatic(Type.getType( field.javaField.getDeclaringClass()), field.javaField.getName(), MethodWriter.getType(field.typeParameter)); } else { - writer.getField(Type.getType( + methodWriter.getField(Type.getType( field.javaField.getDeclaringClass()), field.javaField.getName(), MethodWriter.getType(field.typeParameter)); } } @@ -94,32 +95,32 @@ void updateActual(Class actual) { } @Override - void setup(MethodWriter writer, Globals globals) { + void setup(ClassWriter classWriter, MethodWriter methodWriter,Globals globals) { // Do nothing. } @Override - void load(MethodWriter writer, Globals globals) { - writer.writeDebugInfo(location); + void load(ClassWriter classWriter, MethodWriter methodWriter,Globals globals) { + methodWriter.writeDebugInfo(location); if (java.lang.reflect.Modifier.isStatic(field.javaField.getModifiers())) { - writer.getStatic(Type.getType( + methodWriter.getStatic(Type.getType( field.javaField.getDeclaringClass()), field.javaField.getName(), MethodWriter.getType(field.typeParameter)); } else { - writer.getField(Type.getType( + methodWriter.getField(Type.getType( field.javaField.getDeclaringClass()), field.javaField.getName(), MethodWriter.getType(field.typeParameter)); } } @Override - void store(MethodWriter writer, Globals globals) { - writer.writeDebugInfo(location); + void store(ClassWriter classWriter, MethodWriter methodWriter,Globals globals) { + methodWriter.writeDebugInfo(location); if (java.lang.reflect.Modifier.isStatic(field.javaField.getModifiers())) { - writer.putStatic(Type.getType( + methodWriter.putStatic(Type.getType( field.javaField.getDeclaringClass()), field.javaField.getName(), MethodWriter.getType(field.typeParameter)); } else { - writer.putField(Type.getType( + methodWriter.putField(Type.getType( field.javaField.getDeclaringClass()), field.javaField.getName(), MethodWriter.getType(field.typeParameter)); } } diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/PSubListShortcut.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/PSubListShortcut.java index 0e730cdf9be7d..aa6a807ba7103 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/PSubListShortcut.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/PSubListShortcut.java @@ -19,6 +19,7 @@ package org.elasticsearch.painless.node; +import org.elasticsearch.painless.ClassWriter; import org.elasticsearch.painless.CompilerSettings; import org.elasticsearch.painless.Globals; import org.elasticsearch.painless.Locals; @@ -92,9 +93,9 @@ void analyze(Locals locals) { } @Override - void write(MethodWriter writer, Globals globals) { - setup(writer, globals); - load(writer, globals); + void write(ClassWriter classWriter, MethodWriter methodWriter, Globals globals) { + setup(classWriter, methodWriter, globals); + load(classWriter, methodWriter, globals); } @Override @@ -113,28 +114,28 @@ void updateActual(Class actual) { } @Override - void setup(MethodWriter writer, Globals globals) { - index.write(writer, globals); - writeIndexFlip(writer, w -> { + void setup(ClassWriter classWriter, MethodWriter methodWriter, Globals globals) { + index.write(classWriter, methodWriter, globals); + writeIndexFlip(methodWriter, w -> { w.invokeInterface(WriterConstants.COLLECTION_TYPE, WriterConstants.COLLECTION_SIZE); }); } @Override - void load(MethodWriter writer, Globals globals) { - writer.writeDebugInfo(location); - writer.invokeMethodCall(getter); + void load(ClassWriter classWriter, MethodWriter methodWriter, Globals globals) { + methodWriter.writeDebugInfo(location); + methodWriter.invokeMethodCall(getter); if (getter.returnType == getter.javaMethod.getReturnType()) { - writer.checkCast(MethodWriter.getType(getter.returnType)); + methodWriter.checkCast(MethodWriter.getType(getter.returnType)); } } @Override - void store(MethodWriter writer, Globals globals) { - writer.writeDebugInfo(location); - writer.invokeMethodCall(setter); - writer.writePop(MethodWriter.getType(setter.returnType).getSize()); + void store(ClassWriter classWriter, MethodWriter methodWriter, Globals globals) { + methodWriter.writeDebugInfo(location); + methodWriter.invokeMethodCall(setter); + methodWriter.writePop(MethodWriter.getType(setter.returnType).getSize()); } @Override diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/PSubMapShortcut.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/PSubMapShortcut.java index a3e1ff4d19845..cfbee9313805e 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/PSubMapShortcut.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/PSubMapShortcut.java @@ -19,6 +19,7 @@ package org.elasticsearch.painless.node; +import org.elasticsearch.painless.ClassWriter; import org.elasticsearch.painless.CompilerSettings; import org.elasticsearch.painless.Globals; import org.elasticsearch.painless.Locals; @@ -90,14 +91,14 @@ void analyze(Locals locals) { } @Override - void write(MethodWriter writer, Globals globals) { - index.write(writer, globals); + void write(ClassWriter classWriter, MethodWriter methodWriter, Globals globals) { + index.write(classWriter, methodWriter, globals); - writer.writeDebugInfo(location); - writer.invokeMethodCall(getter); + methodWriter.writeDebugInfo(location); + methodWriter.invokeMethodCall(getter); if (getter.returnType != getter.javaMethod.getReturnType()) { - writer.checkCast(MethodWriter.getType(getter.returnType)); + methodWriter.checkCast(MethodWriter.getType(getter.returnType)); } } @@ -117,25 +118,25 @@ void updateActual(Class actual) { } @Override - void setup(MethodWriter writer, Globals globals) { - index.write(writer, globals); + void setup(ClassWriter classWriter, MethodWriter methodWriter, Globals globals) { + index.write(classWriter, methodWriter, globals); } @Override - void load(MethodWriter writer, Globals globals) { - writer.writeDebugInfo(location); - writer.invokeMethodCall(getter); + void load(ClassWriter classWriter, MethodWriter methodWriter, Globals globals) { + methodWriter.writeDebugInfo(location); + methodWriter.invokeMethodCall(getter); if (getter.returnType != getter.javaMethod.getReturnType()) { - writer.checkCast(MethodWriter.getType(getter.returnType)); + methodWriter.checkCast(MethodWriter.getType(getter.returnType)); } } @Override - void store(MethodWriter writer, Globals globals) { - writer.writeDebugInfo(location); - writer.invokeMethodCall(setter); - writer.writePop(MethodWriter.getType(setter.returnType).getSize()); + void store(ClassWriter classWriter, MethodWriter methodWriter, Globals globals) { + methodWriter.writeDebugInfo(location); + methodWriter.invokeMethodCall(setter); + methodWriter.writePop(MethodWriter.getType(setter.returnType).getSize()); } @Override diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/PSubNullSafeCallInvoke.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/PSubNullSafeCallInvoke.java index 5a450808388d4..91c060372f315 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/PSubNullSafeCallInvoke.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/PSubNullSafeCallInvoke.java @@ -19,6 +19,7 @@ package org.elasticsearch.painless.node; +import org.elasticsearch.painless.ClassWriter; import org.elasticsearch.painless.CompilerSettings; import org.elasticsearch.painless.Globals; import org.elasticsearch.painless.Locals; @@ -64,14 +65,14 @@ void analyze(Locals locals) { } @Override - void write(MethodWriter writer, Globals globals) { - writer.writeDebugInfo(location); + void write(ClassWriter classWriter, MethodWriter methodWriter, Globals globals) { + methodWriter.writeDebugInfo(location); Label end = new Label(); - writer.dup(); - writer.ifNull(end); - guarded.write(writer, globals); - writer.mark(end); + methodWriter.dup(); + methodWriter.ifNull(end); + guarded.write(classWriter, methodWriter, globals); + methodWriter.mark(end); } @Override diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/PSubNullSafeField.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/PSubNullSafeField.java index aa8bc005eae46..96f9774ee5e26 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/PSubNullSafeField.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/PSubNullSafeField.java @@ -19,6 +19,7 @@ package org.elasticsearch.painless.node; +import org.elasticsearch.painless.ClassWriter; import org.elasticsearch.painless.CompilerSettings; import org.elasticsearch.painless.Globals; import org.elasticsearch.painless.Locals; @@ -79,26 +80,26 @@ void updateActual(Class actual) { } @Override - void write(MethodWriter writer, Globals globals) { + void write(ClassWriter classWriter, MethodWriter methodWriter, Globals globals) { Label end = new Label(); - writer.dup(); - writer.ifNull(end); - guarded.write(writer, globals); - writer.mark(end); + methodWriter.dup(); + methodWriter.ifNull(end); + guarded.write(classWriter, methodWriter, globals); + methodWriter.mark(end); } @Override - void setup(MethodWriter writer, Globals globals) { + void setup(ClassWriter classWriter, MethodWriter methodWriter, Globals globals) { throw createError(new IllegalArgumentException("Can't write to null safe field")); } @Override - void load(MethodWriter writer, Globals globals) { + void load(ClassWriter classWriter, MethodWriter methodWriter, Globals globals) { throw createError(new IllegalArgumentException("Can't write to null safe field")); } @Override - void store(MethodWriter writer, Globals globals) { + void store(ClassWriter classWriter, MethodWriter methodWriter, Globals globals) { throw createError(new IllegalArgumentException("Can't write to null safe field")); } diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/PSubShortcut.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/PSubShortcut.java index 4737eb93030a5..9635eb693ecfe 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/PSubShortcut.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/PSubShortcut.java @@ -19,6 +19,7 @@ package org.elasticsearch.painless.node; +import org.elasticsearch.painless.ClassWriter; import org.elasticsearch.painless.CompilerSettings; import org.elasticsearch.painless.Globals; import org.elasticsearch.painless.Locals; @@ -81,13 +82,13 @@ void analyze(Locals locals) { } @Override - void write(MethodWriter writer, Globals globals) { - writer.writeDebugInfo(location); + void write(ClassWriter classWriter, MethodWriter methodWriter, Globals globals) { + methodWriter.writeDebugInfo(location); - writer.invokeMethodCall(getter); + methodWriter.invokeMethodCall(getter); if (!getter.returnType.equals(getter.javaMethod.getReturnType())) { - writer.checkCast(MethodWriter.getType(getter.returnType)); + methodWriter.checkCast(MethodWriter.getType(getter.returnType)); } } @@ -107,28 +108,28 @@ void updateActual(Class actual) { } @Override - void setup(MethodWriter writer, Globals globals) { + void setup(ClassWriter classWriter, MethodWriter methodWriter, Globals globals) { // Do nothing. } @Override - void load(MethodWriter writer, Globals globals) { - writer.writeDebugInfo(location); + void load(ClassWriter classWriter, MethodWriter methodWriter, Globals globals) { + methodWriter.writeDebugInfo(location); - writer.invokeMethodCall(getter); + methodWriter.invokeMethodCall(getter); if (getter.returnType != getter.javaMethod.getReturnType()) { - writer.checkCast(MethodWriter.getType(getter.returnType)); + methodWriter.checkCast(MethodWriter.getType(getter.returnType)); } } @Override - void store(MethodWriter writer, Globals globals) { - writer.writeDebugInfo(location); + void store(ClassWriter classWriter, MethodWriter methodWriter, Globals globals) { + methodWriter.writeDebugInfo(location); - writer.invokeMethodCall(setter); + methodWriter.invokeMethodCall(setter); - writer.writePop(MethodWriter.getType(setter.returnType).getSize()); + methodWriter.writePop(MethodWriter.getType(setter.returnType).getSize()); } @Override diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SBlock.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SBlock.java index 8cfd32a284485..274156d449540 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SBlock.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SBlock.java @@ -19,6 +19,7 @@ package org.elasticsearch.painless.node; +import org.elasticsearch.painless.ClassWriter; import org.elasticsearch.painless.CompilerSettings; import org.elasticsearch.painless.Globals; import org.elasticsearch.painless.Locals; @@ -89,11 +90,11 @@ void analyze(Locals locals) { } @Override - void write(MethodWriter writer, Globals globals) { + void write(ClassWriter classWriter, MethodWriter methodWriter, Globals globals) { for (AStatement statement : statements) { statement.continu = continu; statement.brake = brake; - statement.write(writer, globals); + statement.write(classWriter, methodWriter, globals); } } diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SBreak.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SBreak.java index b1c99988cccf8..2300bd96b427c 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SBreak.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SBreak.java @@ -19,6 +19,7 @@ package org.elasticsearch.painless.node; +import org.elasticsearch.painless.ClassWriter; import org.elasticsearch.painless.CompilerSettings; import org.elasticsearch.painless.Globals; import org.elasticsearch.painless.Locals; @@ -59,8 +60,8 @@ void analyze(Locals locals) { } @Override - void write(MethodWriter writer, Globals globals) { - writer.goTo(brake); + void write(ClassWriter classWriter, MethodWriter methodWriter, Globals globals) { + methodWriter.goTo(brake); } @Override diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SCatch.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SCatch.java index 82363c4bc92b7..37ce42f76e53b 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SCatch.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SCatch.java @@ -19,6 +19,7 @@ package org.elasticsearch.painless.node; +import org.elasticsearch.painless.ClassWriter; import org.elasticsearch.painless.CompilerSettings; import org.elasticsearch.painless.Globals; import org.elasticsearch.painless.Locals; @@ -101,24 +102,24 @@ void analyze(Locals locals) { } @Override - void write(MethodWriter writer, Globals globals) { - writer.writeStatementOffset(location); + void write(ClassWriter classWriter, MethodWriter methodWriter, Globals globals) { + methodWriter.writeStatementOffset(location); Label jump = new Label(); - writer.mark(jump); - writer.visitVarInsn(MethodWriter.getType(variable.clazz).getOpcode(Opcodes.ISTORE), variable.getSlot()); + methodWriter.mark(jump); + methodWriter.visitVarInsn(MethodWriter.getType(variable.clazz).getOpcode(Opcodes.ISTORE), variable.getSlot()); if (block != null) { block.continu = continu; block.brake = brake; - block.write(writer, globals); + block.write(classWriter, methodWriter, globals); } - writer.visitTryCatchBlock(begin, end, jump, MethodWriter.getType(variable.clazz).getInternalName()); + methodWriter.visitTryCatchBlock(begin, end, jump, MethodWriter.getType(variable.clazz).getInternalName()); if (exception != null && (block == null || !block.allEscape)) { - writer.goTo(exception); + methodWriter.goTo(exception); } } diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SClass.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SClass.java index 0d15aec23b17d..d44196273873e 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SClass.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SClass.java @@ -19,6 +19,7 @@ package org.elasticsearch.painless.node; +import org.elasticsearch.painless.ClassWriter; import org.elasticsearch.painless.CompilerSettings; import org.elasticsearch.painless.Constant; import org.elasticsearch.painless.Globals; @@ -28,16 +29,13 @@ import org.elasticsearch.painless.Location; import org.elasticsearch.painless.MethodWriter; import org.elasticsearch.painless.ScriptClassInfo; -import org.elasticsearch.painless.SimpleChecksAdapter; import org.elasticsearch.painless.WriterConstants; import org.elasticsearch.painless.lookup.PainlessLookup; import org.objectweb.asm.ClassVisitor; -import org.objectweb.asm.ClassWriter; import org.objectweb.asm.Label; import org.objectweb.asm.Opcodes; import org.objectweb.asm.Type; import org.objectweb.asm.util.Printer; -import org.objectweb.asm.util.TraceClassVisitor; import java.lang.invoke.MethodType; import java.util.ArrayList; @@ -199,30 +197,19 @@ void analyze(Locals program) { public Map write() { // Create the ClassWriter. - int classFrames = ClassWriter.COMPUTE_FRAMES | ClassWriter.COMPUTE_MAXS; + int classFrames = org.objectweb.asm.ClassWriter.COMPUTE_FRAMES | org.objectweb.asm.ClassWriter.COMPUTE_MAXS; int classAccess = Opcodes.ACC_PUBLIC | Opcodes.ACC_SUPER | Opcodes.ACC_FINAL; String interfaceBase = BASE_INTERFACE_TYPE.getInternalName(); String className = CLASS_TYPE.getInternalName(); - String classInterfaces[] = new String[] { interfaceBase }; + String[] classInterfaces = new String[] { interfaceBase }; - ClassWriter writer = new ClassWriter(classFrames); - ClassVisitor visitor = writer; - - // if picky is enabled, turn on some checks. instead of VerifyError at the end, you get a helpful stacktrace. - if (settings.isPicky()) { - visitor = new SimpleChecksAdapter(visitor); - } - - if (debugStream != null) { - visitor = new TraceClassVisitor(visitor, debugStream, null); - } - visitor.visit(WriterConstants.CLASS_VERSION, classAccess, className, null, - Type.getType(scriptClassInfo.getBaseClass()).getInternalName(), classInterfaces); - visitor.visitSource(Location.computeSourceName(name), null); + ClassWriter classWriter = new ClassWriter(settings, globals.getStatements(), debugStream, + scriptClassInfo.getBaseClass(), classFrames, classAccess, className, classInterfaces); + ClassVisitor classVisitor = classWriter.getClassVisitor(); + classVisitor.visitSource(Location.computeSourceName(name), null); // Write the a method to bootstrap def calls - MethodWriter bootstrapDef = new MethodWriter(Opcodes.ACC_STATIC | Opcodes.ACC_VARARGS, DEF_BOOTSTRAP_METHOD, visitor, - globals.getStatements(), settings); + MethodWriter bootstrapDef = classWriter.newMethodWriter(Opcodes.ACC_STATIC | Opcodes.ACC_VARARGS, DEF_BOOTSTRAP_METHOD); bootstrapDef.visitCode(); bootstrapDef.getStatic(CLASS_TYPE, "$DEFINITION", DEFINITION_TYPE); bootstrapDef.getStatic(CLASS_TYPE, "$LOCALS", MAP_TYPE); @@ -232,13 +219,14 @@ public Map write() { bootstrapDef.endMethod(); // Write static variables for name, source and statements used for writing exception messages - visitor.visitField(Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC, "$NAME", STRING_TYPE.getDescriptor(), null, null).visitEnd(); - visitor.visitField(Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC, "$SOURCE", STRING_TYPE.getDescriptor(), null, null).visitEnd(); - visitor.visitField(Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC, "$STATEMENTS", BITSET_TYPE.getDescriptor(), null, null).visitEnd(); + classVisitor.visitField(Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC, "$NAME", STRING_TYPE.getDescriptor(), null, null).visitEnd(); + classVisitor.visitField(Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC, "$SOURCE", STRING_TYPE.getDescriptor(), null, null).visitEnd(); + classVisitor.visitField(Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC, "$STATEMENTS", BITSET_TYPE.getDescriptor(), null, null).visitEnd(); // Write the static variables used by the method to bootstrap def calls - visitor.visitField(Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC, "$DEFINITION", DEFINITION_TYPE.getDescriptor(), null, null).visitEnd(); - visitor.visitField(Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC, "$LOCALS", MAP_TYPE.getDescriptor(), null, null).visitEnd(); + classVisitor.visitField( + Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC, "$DEFINITION", DEFINITION_TYPE.getDescriptor(), null, null).visitEnd(); + classVisitor.visitField(Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC, "$LOCALS", MAP_TYPE.getDescriptor(), null, null).visitEnd(); org.objectweb.asm.commons.Method init; @@ -250,7 +238,7 @@ public Map write() { } // Write the constructor: - MethodWriter constructor = new MethodWriter(Opcodes.ACC_PUBLIC, init, visitor, globals.getStatements(), settings); + MethodWriter constructor = classWriter.newMethodWriter(Opcodes.ACC_PUBLIC, init); constructor.visitCode(); constructor.loadThis(); constructor.loadArgs(); @@ -259,37 +247,35 @@ public Map write() { constructor.endMethod(); // Write a method to get static variable source - MethodWriter nameMethod = new MethodWriter(Opcodes.ACC_PUBLIC, GET_NAME_METHOD, visitor, globals.getStatements(), settings); + MethodWriter nameMethod = classWriter.newMethodWriter(Opcodes.ACC_PUBLIC, GET_NAME_METHOD); nameMethod.visitCode(); nameMethod.getStatic(CLASS_TYPE, "$NAME", STRING_TYPE); nameMethod.returnValue(); nameMethod.endMethod(); // Write a method to get static variable source - MethodWriter sourceMethod = new MethodWriter(Opcodes.ACC_PUBLIC, GET_SOURCE_METHOD, visitor, globals.getStatements(), settings); + MethodWriter sourceMethod = classWriter.newMethodWriter(Opcodes.ACC_PUBLIC, GET_SOURCE_METHOD); sourceMethod.visitCode(); sourceMethod.getStatic(CLASS_TYPE, "$SOURCE", STRING_TYPE); sourceMethod.returnValue(); sourceMethod.endMethod(); // Write a method to get static variable statements - MethodWriter statementsMethod = - new MethodWriter(Opcodes.ACC_PUBLIC, GET_STATEMENTS_METHOD, visitor, globals.getStatements(), settings); + MethodWriter statementsMethod = classWriter.newMethodWriter(Opcodes.ACC_PUBLIC, GET_STATEMENTS_METHOD); statementsMethod.visitCode(); statementsMethod.getStatic(CLASS_TYPE, "$STATEMENTS", BITSET_TYPE); statementsMethod.returnValue(); statementsMethod.endMethod(); // Write the method defined in the interface: - MethodWriter executeMethod = new MethodWriter(Opcodes.ACC_PUBLIC, scriptClassInfo.getExecuteMethod(), visitor, - globals.getStatements(), settings); + MethodWriter executeMethod = classWriter.newMethodWriter(Opcodes.ACC_PUBLIC, scriptClassInfo.getExecuteMethod()); executeMethod.visitCode(); - write(executeMethod, globals); + write(classWriter, executeMethod, globals); executeMethod.endMethod(); // Write all functions: for (SFunction function : functions) { - function.write(visitor, settings, globals); + function.write(classWriter, globals); } // Write all synthetic functions. Note that this process may add more :) @@ -297,7 +283,7 @@ public Map write() { List current = new ArrayList<>(globals.getSyntheticMethods().values()); globals.getSyntheticMethods().clear(); for (SFunction function : current) { - function.write(visitor, settings, globals); + function.write(classWriter, globals); } } @@ -307,7 +293,7 @@ public Map write() { // Fields for (Constant constant : inits) { - visitor.visitField( + classVisitor.visitField( Opcodes.ACC_FINAL | Opcodes.ACC_PRIVATE | Opcodes.ACC_STATIC, constant.name, constant.type.getDescriptor(), @@ -317,7 +303,7 @@ public Map write() { // Initialize the constants in a static initializer final MethodWriter clinit = new MethodWriter(Opcodes.ACC_STATIC, - WriterConstants.CLINIT, visitor, globals.getStatements(), settings); + WriterConstants.CLINIT, classVisitor, globals.getStatements(), settings); clinit.visitCode(); for (Constant constant : inits) { constant.initializer.accept(clinit); @@ -331,14 +317,14 @@ public Map write() { for (Map.Entry> classBinding : globals.getClassBindings().entrySet()) { String name = classBinding.getKey(); String descriptor = Type.getType(classBinding.getValue()).getDescriptor(); - visitor.visitField(Opcodes.ACC_PRIVATE, name, descriptor, null, null).visitEnd(); + classVisitor.visitField(Opcodes.ACC_PRIVATE, name, descriptor, null, null).visitEnd(); } // Write instance binding variables for (Map.Entry instanceBinding : globals.getInstanceBindings().entrySet()) { String name = instanceBinding.getValue(); String descriptor = Type.getType(instanceBinding.getKey().getClass()).getDescriptor(); - visitor.visitField(Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC, name, descriptor, null, null).visitEnd(); + classVisitor.visitField(Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC, name, descriptor, null, null).visitEnd(); } // Write any needsVarName methods for used variables @@ -346,7 +332,7 @@ public Map write() { String name = needsMethod.getName(); name = name.substring(5); name = Character.toLowerCase(name.charAt(0)) + name.substring(1); - MethodWriter ifaceMethod = new MethodWriter(Opcodes.ACC_PUBLIC, needsMethod, visitor, globals.getStatements(), settings); + MethodWriter ifaceMethod = classWriter.newMethodWriter(Opcodes.ACC_PUBLIC, needsMethod); ifaceMethod.visitCode(); ifaceMethod.push(extractedVariables.contains(name)); ifaceMethod.returnValue(); @@ -355,8 +341,8 @@ public Map write() { // End writing the class and store the generated bytes. - visitor.visitEnd(); - bytes = writer.toByteArray(); + classVisitor.visitEnd(); + bytes = classWriter.getClassBytes(); Map statics = new HashMap<>(); statics.put("$LOCALS", mainMethod.getMethods()); @@ -369,14 +355,14 @@ public Map write() { } @Override - void write(MethodWriter writer, Globals globals) { + void write(org.elasticsearch.painless.ClassWriter classWriter, MethodWriter methodWriter, Globals globals) { // We wrap the whole method in a few try/catches to handle and/or convert other exceptions to ScriptException Label startTry = new Label(); Label endTry = new Label(); Label startExplainCatch = new Label(); Label startOtherCatch = new Label(); Label endCatch = new Label(); - writer.mark(startTry); + methodWriter.mark(startTry); if (settings.getMaxLoopCounter() > 0) { // if there is infinite loop protection, we do this once: @@ -384,8 +370,8 @@ void write(MethodWriter writer, Globals globals) { Variable loop = mainMethod.getVariable(null, Locals.LOOP); - writer.push(settings.getMaxLoopCounter()); - writer.visitVarInsn(Opcodes.ISTORE, loop.getSlot()); + methodWriter.push(settings.getMaxLoopCounter()); + methodWriter.visitVarInsn(Opcodes.ISTORE, loop.getSlot()); } for (org.objectweb.asm.commons.Method method : getMethods) { @@ -393,77 +379,77 @@ void write(MethodWriter writer, Globals globals) { name = Character.toLowerCase(name.charAt(0)) + name.substring(1); Variable variable = mainMethod.getVariable(null, name); - writer.loadThis(); - writer.invokeVirtual(Type.getType(scriptClassInfo.getBaseClass()), method); - writer.visitVarInsn(method.getReturnType().getOpcode(Opcodes.ISTORE), variable.getSlot()); + methodWriter.loadThis(); + methodWriter.invokeVirtual(Type.getType(scriptClassInfo.getBaseClass()), method); + methodWriter.visitVarInsn(method.getReturnType().getOpcode(Opcodes.ISTORE), variable.getSlot()); } for (AStatement statement : statements) { - statement.write(writer, globals); + statement.write(classWriter, methodWriter, globals); } if (!methodEscape) { switch (scriptClassInfo.getExecuteMethod().getReturnType().getSort()) { case org.objectweb.asm.Type.VOID: break; case org.objectweb.asm.Type.BOOLEAN: - writer.push(false); + methodWriter.push(false); break; case org.objectweb.asm.Type.BYTE: - writer.push(0); + methodWriter.push(0); break; case org.objectweb.asm.Type.SHORT: - writer.push(0); + methodWriter.push(0); break; case org.objectweb.asm.Type.INT: - writer.push(0); + methodWriter.push(0); break; case org.objectweb.asm.Type.LONG: - writer.push(0L); + methodWriter.push(0L); break; case org.objectweb.asm.Type.FLOAT: - writer.push(0f); + methodWriter.push(0f); break; case org.objectweb.asm.Type.DOUBLE: - writer.push(0d); + methodWriter.push(0d); break; default: - writer.visitInsn(Opcodes.ACONST_NULL); + methodWriter.visitInsn(Opcodes.ACONST_NULL); } - writer.returnValue(); + methodWriter.returnValue(); } - writer.mark(endTry); - writer.goTo(endCatch); + methodWriter.mark(endTry); + methodWriter.goTo(endCatch); // This looks like: // } catch (PainlessExplainError e) { // throw this.convertToScriptException(e, e.getHeaders($DEFINITION)) // } - writer.visitTryCatchBlock(startTry, endTry, startExplainCatch, PAINLESS_EXPLAIN_ERROR_TYPE.getInternalName()); - writer.mark(startExplainCatch); - writer.loadThis(); - writer.swap(); - writer.dup(); - writer.getStatic(CLASS_TYPE, "$DEFINITION", DEFINITION_TYPE); - writer.invokeVirtual(PAINLESS_EXPLAIN_ERROR_TYPE, PAINLESS_EXPLAIN_ERROR_GET_HEADERS_METHOD); - writer.invokeInterface(BASE_INTERFACE_TYPE, CONVERT_TO_SCRIPT_EXCEPTION_METHOD); - writer.throwException(); + methodWriter.visitTryCatchBlock(startTry, endTry, startExplainCatch, PAINLESS_EXPLAIN_ERROR_TYPE.getInternalName()); + methodWriter.mark(startExplainCatch); + methodWriter.loadThis(); + methodWriter.swap(); + methodWriter.dup(); + methodWriter.getStatic(CLASS_TYPE, "$DEFINITION", DEFINITION_TYPE); + methodWriter.invokeVirtual(PAINLESS_EXPLAIN_ERROR_TYPE, PAINLESS_EXPLAIN_ERROR_GET_HEADERS_METHOD); + methodWriter.invokeInterface(BASE_INTERFACE_TYPE, CONVERT_TO_SCRIPT_EXCEPTION_METHOD); + methodWriter.throwException(); // This looks like: // } catch (PainlessError | BootstrapMethodError | OutOfMemoryError | StackOverflowError | Exception e) { // throw this.convertToScriptException(e, e.getHeaders()) // } // We *think* it is ok to catch OutOfMemoryError and StackOverflowError because Painless is stateless - writer.visitTryCatchBlock(startTry, endTry, startOtherCatch, PAINLESS_ERROR_TYPE.getInternalName()); - writer.visitTryCatchBlock(startTry, endTry, startOtherCatch, BOOTSTRAP_METHOD_ERROR_TYPE.getInternalName()); - writer.visitTryCatchBlock(startTry, endTry, startOtherCatch, OUT_OF_MEMORY_ERROR_TYPE.getInternalName()); - writer.visitTryCatchBlock(startTry, endTry, startOtherCatch, STACK_OVERFLOW_ERROR_TYPE.getInternalName()); - writer.visitTryCatchBlock(startTry, endTry, startOtherCatch, EXCEPTION_TYPE.getInternalName()); - writer.mark(startOtherCatch); - writer.loadThis(); - writer.swap(); - writer.invokeStatic(COLLECTIONS_TYPE, EMPTY_MAP_METHOD); - writer.invokeInterface(BASE_INTERFACE_TYPE, CONVERT_TO_SCRIPT_EXCEPTION_METHOD); - writer.throwException(); - writer.mark(endCatch); + methodWriter.visitTryCatchBlock(startTry, endTry, startOtherCatch, PAINLESS_ERROR_TYPE.getInternalName()); + methodWriter.visitTryCatchBlock(startTry, endTry, startOtherCatch, BOOTSTRAP_METHOD_ERROR_TYPE.getInternalName()); + methodWriter.visitTryCatchBlock(startTry, endTry, startOtherCatch, OUT_OF_MEMORY_ERROR_TYPE.getInternalName()); + methodWriter.visitTryCatchBlock(startTry, endTry, startOtherCatch, STACK_OVERFLOW_ERROR_TYPE.getInternalName()); + methodWriter.visitTryCatchBlock(startTry, endTry, startOtherCatch, EXCEPTION_TYPE.getInternalName()); + methodWriter.mark(startOtherCatch); + methodWriter.loadThis(); + methodWriter.swap(); + methodWriter.invokeStatic(COLLECTIONS_TYPE, EMPTY_MAP_METHOD); + methodWriter.invokeInterface(BASE_INTERFACE_TYPE, CONVERT_TO_SCRIPT_EXCEPTION_METHOD); + methodWriter.throwException(); + methodWriter.mark(endCatch); } public BitSet getStatements() { diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SContinue.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SContinue.java index 18a0fe33cae13..07238096b4afe 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SContinue.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SContinue.java @@ -19,6 +19,7 @@ package org.elasticsearch.painless.node; +import org.elasticsearch.painless.ClassWriter; import org.elasticsearch.painless.CompilerSettings; import org.elasticsearch.painless.Globals; import org.elasticsearch.painless.Locals; @@ -62,8 +63,8 @@ void analyze(Locals locals) { } @Override - void write(MethodWriter writer, Globals globals) { - writer.goTo(continu); + void write(ClassWriter classWriter, MethodWriter methodWriter, Globals globals) { + methodWriter.goTo(continu); } @Override diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SDeclBlock.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SDeclBlock.java index 5a68ca1a450b5..775f65f34da12 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SDeclBlock.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SDeclBlock.java @@ -19,6 +19,7 @@ package org.elasticsearch.painless.node; +import org.elasticsearch.painless.ClassWriter; import org.elasticsearch.painless.CompilerSettings; import org.elasticsearch.painless.Globals; import org.elasticsearch.painless.Locals; @@ -68,9 +69,9 @@ void analyze(Locals locals) { } @Override - void write(MethodWriter writer, Globals globals) { + void write(ClassWriter classWriter, MethodWriter methodWriter, Globals globals) { for (AStatement declaration : declarations) { - declaration.write(writer, globals); + declaration.write(classWriter, methodWriter, globals); } } diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SDeclaration.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SDeclaration.java index e731555e20a7c..f4548849fc085 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SDeclaration.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SDeclaration.java @@ -19,6 +19,7 @@ package org.elasticsearch.painless.node; +import org.elasticsearch.painless.ClassWriter; import org.elasticsearch.painless.CompilerSettings; import org.elasticsearch.painless.Globals; import org.elasticsearch.painless.Locals; @@ -83,29 +84,29 @@ void analyze(Locals locals) { } @Override - void write(MethodWriter writer, Globals globals) { - writer.writeStatementOffset(location); + void write(ClassWriter classWriter, MethodWriter methodWriter, Globals globals) { + methodWriter.writeStatementOffset(location); if (expression == null) { Class sort = variable.clazz; if (sort == void.class || sort == boolean.class || sort == byte.class || sort == short.class || sort == char.class || sort == int.class) { - writer.push(0); + methodWriter.push(0); } else if (sort == long.class) { - writer.push(0L); + methodWriter.push(0L); } else if (sort == float.class) { - writer.push(0F); + methodWriter.push(0F); } else if (sort == double.class) { - writer.push(0D); + methodWriter.push(0D); } else { - writer.visitInsn(Opcodes.ACONST_NULL); + methodWriter.visitInsn(Opcodes.ACONST_NULL); } } else { - expression.write(writer, globals); + expression.write(classWriter, methodWriter, globals); } - writer.visitVarInsn(MethodWriter.getType(variable.clazz).getOpcode(Opcodes.ISTORE), variable.getSlot()); + methodWriter.visitVarInsn(MethodWriter.getType(variable.clazz).getOpcode(Opcodes.ISTORE), variable.getSlot()); } @Override diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SDo.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SDo.java index 04a386d763ec1..80cacd5eb306b 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SDo.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SDo.java @@ -19,6 +19,7 @@ package org.elasticsearch.painless.node; +import org.elasticsearch.painless.ClassWriter; import org.elasticsearch.painless.CompilerSettings; import org.elasticsearch.painless.Globals; import org.elasticsearch.painless.Locals; @@ -107,32 +108,32 @@ void analyze(Locals locals) { } @Override - void write(MethodWriter writer, Globals globals) { - writer.writeStatementOffset(location); + void write(ClassWriter classWriter, MethodWriter methodWriter, Globals globals) { + methodWriter.writeStatementOffset(location); Label start = new Label(); Label begin = new Label(); Label end = new Label(); - writer.mark(start); + methodWriter.mark(start); block.continu = begin; block.brake = end; - block.write(writer, globals); + block.write(classWriter, methodWriter, globals); - writer.mark(begin); + methodWriter.mark(begin); if (!continuous) { - condition.write(writer, globals); - writer.ifZCmp(Opcodes.IFEQ, end); + condition.write(classWriter, methodWriter, globals); + methodWriter.ifZCmp(Opcodes.IFEQ, end); } if (loopCounter != null) { - writer.writeLoopCounter(loopCounter.getSlot(), Math.max(1, block.statementCount), location); + methodWriter.writeLoopCounter(loopCounter.getSlot(), Math.max(1, block.statementCount), location); } - writer.goTo(start); - writer.mark(end); + methodWriter.goTo(start); + methodWriter.mark(end); } @Override diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SEach.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SEach.java index 2e9dd826f9919..fe9b3264ad5ed 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SEach.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SEach.java @@ -19,6 +19,7 @@ package org.elasticsearch.painless.node; +import org.elasticsearch.painless.ClassWriter; import org.elasticsearch.painless.CompilerSettings; import org.elasticsearch.painless.Globals; import org.elasticsearch.painless.Locals; @@ -119,8 +120,8 @@ void analyze(Locals locals) { } @Override - void write(MethodWriter writer, Globals globals) { - sub.write(writer, globals); + void write(ClassWriter classWriter, MethodWriter methodWriter, Globals globals) { + sub.write(classWriter, methodWriter, globals); } @Override diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SExpression.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SExpression.java index e1ee2e6e5bd35..c4b5c7883a689 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SExpression.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SExpression.java @@ -19,6 +19,7 @@ package org.elasticsearch.painless.node; +import org.elasticsearch.painless.ClassWriter; import org.elasticsearch.painless.CompilerSettings; import org.elasticsearch.painless.Globals; import org.elasticsearch.painless.Locals; @@ -76,14 +77,14 @@ void analyze(Locals locals) { } @Override - void write(MethodWriter writer, Globals globals) { - writer.writeStatementOffset(location); - expression.write(writer, globals); + void write(ClassWriter classWriter, MethodWriter methodWriter, Globals globals) { + methodWriter.writeStatementOffset(location); + expression.write(classWriter, methodWriter, globals); if (methodEscape) { - writer.returnValue(); + methodWriter.returnValue(); } else { - writer.writePop(MethodWriter.getType(expression.expected).getSize()); + methodWriter.writePop(MethodWriter.getType(expression.expected).getSize()); } } diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SFor.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SFor.java index 14580a1d65b1b..d6bf4ff5b163e 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SFor.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SFor.java @@ -19,6 +19,7 @@ package org.elasticsearch.painless.node; +import org.elasticsearch.painless.ClassWriter; import org.elasticsearch.painless.CompilerSettings; import org.elasticsearch.painless.Globals; import org.elasticsearch.painless.Locals; @@ -173,27 +174,27 @@ void analyze(Locals locals) { } @Override - void write(MethodWriter writer, Globals globals) { - writer.writeStatementOffset(location); + void write(ClassWriter classWriter, MethodWriter methodWriter, Globals globals) { + methodWriter.writeStatementOffset(location); Label start = new Label(); Label begin = afterthought == null ? start : new Label(); Label end = new Label(); if (initializer instanceof SDeclBlock) { - initializer.write(writer, globals); + initializer.write(classWriter, methodWriter, globals); } else if (initializer instanceof AExpression) { AExpression initializer = (AExpression)this.initializer; - initializer.write(writer, globals); - writer.writePop(MethodWriter.getType(initializer.expected).getSize()); + initializer.write(classWriter, methodWriter, globals); + methodWriter.writePop(MethodWriter.getType(initializer.expected).getSize()); } - writer.mark(start); + methodWriter.mark(start); if (condition != null && !continuous) { - condition.write(writer, globals); - writer.ifZCmp(Opcodes.IFEQ, end); + condition.write(classWriter, methodWriter, globals); + methodWriter.ifZCmp(Opcodes.IFEQ, end); } boolean allEscape = false; @@ -208,29 +209,29 @@ void write(MethodWriter writer, Globals globals) { } if (loopCounter != null) { - writer.writeLoopCounter(loopCounter.getSlot(), statementCount, location); + methodWriter.writeLoopCounter(loopCounter.getSlot(), statementCount, location); } block.continu = begin; block.brake = end; - block.write(writer, globals); + block.write(classWriter, methodWriter, globals); } else { if (loopCounter != null) { - writer.writeLoopCounter(loopCounter.getSlot(), 1, location); + methodWriter.writeLoopCounter(loopCounter.getSlot(), 1, location); } } if (afterthought != null) { - writer.mark(begin); - afterthought.write(writer, globals); - writer.writePop(MethodWriter.getType(afterthought.expected).getSize()); + methodWriter.mark(begin); + afterthought.write(classWriter, methodWriter, globals); + methodWriter.writePop(MethodWriter.getType(afterthought.expected).getSize()); } if (afterthought != null || !allEscape) { - writer.goTo(start); + methodWriter.goTo(start); } - writer.mark(end); + methodWriter.mark(end); } @Override diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SFunction.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SFunction.java index 21f64f16352fb..3d67d2d1a4b61 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SFunction.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SFunction.java @@ -19,6 +19,7 @@ package org.elasticsearch.painless.node; +import org.elasticsearch.painless.ClassWriter; import org.elasticsearch.painless.CompilerSettings; import org.elasticsearch.painless.Globals; import org.elasticsearch.painless.Locals; @@ -28,7 +29,6 @@ import org.elasticsearch.painless.MethodWriter; import org.elasticsearch.painless.lookup.PainlessLookup; import org.elasticsearch.painless.lookup.PainlessLookupUtility; -import org.objectweb.asm.ClassVisitor; import org.objectweb.asm.Opcodes; import java.lang.invoke.MethodType; @@ -146,31 +146,31 @@ void analyze(Locals locals) { } /** Writes the function to given ClassVisitor. */ - void write(ClassVisitor writer, CompilerSettings settings, Globals globals) { + void write(ClassWriter classWriter, Globals globals) { int access = Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC; if (synthetic) { access |= Opcodes.ACC_SYNTHETIC; } - final MethodWriter function = new MethodWriter(access, method, writer, globals.getStatements(), settings); - function.visitCode(); - write(function, globals); - function.endMethod(); + final MethodWriter methodWriter = classWriter.newMethodWriter(access, method); + methodWriter.visitCode(); + write(classWriter, methodWriter, globals); + methodWriter.endMethod(); } @Override - void write(MethodWriter function, Globals globals) { + void write(ClassWriter classWriter, MethodWriter methodWriter, Globals globals) { if (settings.getMaxLoopCounter() > 0) { // if there is infinite loop protection, we do this once: // int #loop = settings.getMaxLoopCounter() - function.push(settings.getMaxLoopCounter()); - function.visitVarInsn(Opcodes.ISTORE, loop.getSlot()); + methodWriter.push(settings.getMaxLoopCounter()); + methodWriter.visitVarInsn(Opcodes.ISTORE, loop.getSlot()); } - block.write(function, globals); + block.write(classWriter, methodWriter, globals); if (!methodEscape) { if (returnType == void.class) { - function.returnValue(); + methodWriter.returnValue(); } else { throw createError(new IllegalStateException("Illegal tree structure.")); } diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SIf.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SIf.java index 43472d82ccb12..f7e030edca85d 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SIf.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SIf.java @@ -19,6 +19,7 @@ package org.elasticsearch.painless.node; +import org.elasticsearch.painless.ClassWriter; import org.elasticsearch.painless.CompilerSettings; import org.elasticsearch.painless.Globals; import org.elasticsearch.painless.Locals; @@ -89,19 +90,19 @@ void analyze(Locals locals) { } @Override - void write(MethodWriter writer, Globals globals) { - writer.writeStatementOffset(location); + void write(ClassWriter classWriter, MethodWriter methodWriter, Globals globals) { + methodWriter.writeStatementOffset(location); Label fals = new Label(); - condition.write(writer, globals); - writer.ifZCmp(Opcodes.IFEQ, fals); + condition.write(classWriter, methodWriter, globals); + methodWriter.ifZCmp(Opcodes.IFEQ, fals); ifblock.continu = continu; ifblock.brake = brake; - ifblock.write(writer, globals); + ifblock.write(classWriter, methodWriter, globals); - writer.mark(fals); + methodWriter.mark(fals); } @Override diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SIfElse.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SIfElse.java index e4460de645c9b..44eb0f8e816d3 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SIfElse.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SIfElse.java @@ -19,6 +19,7 @@ package org.elasticsearch.painless.node; +import org.elasticsearch.painless.ClassWriter; import org.elasticsearch.painless.CompilerSettings; import org.elasticsearch.painless.Globals; import org.elasticsearch.painless.Locals; @@ -119,30 +120,30 @@ void analyze(Locals locals) { } @Override - void write(MethodWriter writer, Globals globals) { - writer.writeStatementOffset(location); + void write(ClassWriter classWriter, MethodWriter methodWriter, Globals globals) { + methodWriter.writeStatementOffset(location); Label fals = new Label(); Label end = new Label(); - condition.write(writer, globals); - writer.ifZCmp(Opcodes.IFEQ, fals); + condition.write(classWriter, methodWriter, globals); + methodWriter.ifZCmp(Opcodes.IFEQ, fals); ifblock.continu = continu; ifblock.brake = brake; - ifblock.write(writer, globals); + ifblock.write(classWriter, methodWriter, globals); if (!ifblock.allEscape) { - writer.goTo(end); + methodWriter.goTo(end); } - writer.mark(fals); + methodWriter.mark(fals); elseblock.continu = continu; elseblock.brake = brake; - elseblock.write(writer, globals); + elseblock.write(classWriter, methodWriter, globals); - writer.mark(end); + methodWriter.mark(end); } @Override diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SReturn.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SReturn.java index 68d5e286ec6ba..84c357ccdb4c2 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SReturn.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SReturn.java @@ -19,6 +19,7 @@ package org.elasticsearch.painless.node; +import org.elasticsearch.painless.ClassWriter; import org.elasticsearch.painless.CompilerSettings; import org.elasticsearch.painless.Globals; import org.elasticsearch.painless.Locals; @@ -78,14 +79,14 @@ void analyze(Locals locals) { } @Override - void write(MethodWriter writer, Globals globals) { - writer.writeStatementOffset(location); + void write(ClassWriter classWriter, MethodWriter methodWriter, Globals globals) { + methodWriter.writeStatementOffset(location); if (expression != null) { - expression.write(writer, globals); + expression.write(classWriter, methodWriter, globals); } - writer.returnValue(); + methodWriter.returnValue(); } @Override diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SSubEachArray.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SSubEachArray.java index 9a689a428f4b4..c65975e387460 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SSubEachArray.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SSubEachArray.java @@ -20,6 +20,7 @@ package org.elasticsearch.painless.node; import org.elasticsearch.painless.AnalyzerCaster; +import org.elasticsearch.painless.ClassWriter; import org.elasticsearch.painless.CompilerSettings; import org.elasticsearch.painless.Globals; import org.elasticsearch.painless.Locals; @@ -76,41 +77,41 @@ void analyze(Locals locals) { } @Override - void write(MethodWriter writer, Globals globals) { - writer.writeStatementOffset(location); + void write(ClassWriter classWriter, MethodWriter methodWriter, Globals globals) { + methodWriter.writeStatementOffset(location); - expression.write(writer, globals); - writer.visitVarInsn(MethodWriter.getType(array.clazz).getOpcode(Opcodes.ISTORE), array.getSlot()); - writer.push(-1); - writer.visitVarInsn(MethodWriter.getType(index.clazz).getOpcode(Opcodes.ISTORE), index.getSlot()); + expression.write(classWriter, methodWriter, globals); + methodWriter.visitVarInsn(MethodWriter.getType(array.clazz).getOpcode(Opcodes.ISTORE), array.getSlot()); + methodWriter.push(-1); + methodWriter.visitVarInsn(MethodWriter.getType(index.clazz).getOpcode(Opcodes.ISTORE), index.getSlot()); Label begin = new Label(); Label end = new Label(); - writer.mark(begin); + methodWriter.mark(begin); - writer.visitIincInsn(index.getSlot(), 1); - writer.visitVarInsn(MethodWriter.getType(index.clazz).getOpcode(Opcodes.ILOAD), index.getSlot()); - writer.visitVarInsn(MethodWriter.getType(array.clazz).getOpcode(Opcodes.ILOAD), array.getSlot()); - writer.arrayLength(); - writer.ifICmp(MethodWriter.GE, end); + methodWriter.visitIincInsn(index.getSlot(), 1); + methodWriter.visitVarInsn(MethodWriter.getType(index.clazz).getOpcode(Opcodes.ILOAD), index.getSlot()); + methodWriter.visitVarInsn(MethodWriter.getType(array.clazz).getOpcode(Opcodes.ILOAD), array.getSlot()); + methodWriter.arrayLength(); + methodWriter.ifICmp(MethodWriter.GE, end); - writer.visitVarInsn(MethodWriter.getType(array.clazz).getOpcode(Opcodes.ILOAD), array.getSlot()); - writer.visitVarInsn(MethodWriter.getType(index.clazz).getOpcode(Opcodes.ILOAD), index.getSlot()); - writer.arrayLoad(MethodWriter.getType(indexed)); - writer.writeCast(cast); - writer.visitVarInsn(MethodWriter.getType(variable.clazz).getOpcode(Opcodes.ISTORE), variable.getSlot()); + methodWriter.visitVarInsn(MethodWriter.getType(array.clazz).getOpcode(Opcodes.ILOAD), array.getSlot()); + methodWriter.visitVarInsn(MethodWriter.getType(index.clazz).getOpcode(Opcodes.ILOAD), index.getSlot()); + methodWriter.arrayLoad(MethodWriter.getType(indexed)); + methodWriter.writeCast(cast); + methodWriter.visitVarInsn(MethodWriter.getType(variable.clazz).getOpcode(Opcodes.ISTORE), variable.getSlot()); if (loopCounter != null) { - writer.writeLoopCounter(loopCounter.getSlot(), statementCount, location); + methodWriter.writeLoopCounter(loopCounter.getSlot(), statementCount, location); } block.continu = begin; block.brake = end; - block.write(writer, globals); + block.write(classWriter, methodWriter, globals); - writer.goTo(begin); - writer.mark(end); + methodWriter.goTo(begin); + methodWriter.mark(end); } @Override diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SSubEachIterable.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SSubEachIterable.java index c18bc759c3b6a..24658ea569d94 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SSubEachIterable.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SSubEachIterable.java @@ -20,6 +20,7 @@ package org.elasticsearch.painless.node; import org.elasticsearch.painless.AnalyzerCaster; +import org.elasticsearch.painless.ClassWriter; import org.elasticsearch.painless.CompilerSettings; import org.elasticsearch.painless.DefBootstrap; import org.elasticsearch.painless.Globals; @@ -95,45 +96,45 @@ void analyze(Locals locals) { } @Override - void write(MethodWriter writer, Globals globals) { - writer.writeStatementOffset(location); + void write(ClassWriter classWriter, MethodWriter methodWriter, Globals globals) { + methodWriter.writeStatementOffset(location); - expression.write(writer, globals); + expression.write(classWriter, methodWriter, globals); if (method == null) { org.objectweb.asm.Type methodType = org.objectweb.asm.Type .getMethodType(org.objectweb.asm.Type.getType(Iterator.class), org.objectweb.asm.Type.getType(Object.class)); - writer.invokeDefCall("iterator", methodType, DefBootstrap.ITERATOR); + methodWriter.invokeDefCall("iterator", methodType, DefBootstrap.ITERATOR); } else { - writer.invokeMethodCall(method); + methodWriter.invokeMethodCall(method); } - writer.visitVarInsn(MethodWriter.getType(iterator.clazz).getOpcode(Opcodes.ISTORE), iterator.getSlot()); + methodWriter.visitVarInsn(MethodWriter.getType(iterator.clazz).getOpcode(Opcodes.ISTORE), iterator.getSlot()); Label begin = new Label(); Label end = new Label(); - writer.mark(begin); + methodWriter.mark(begin); - writer.visitVarInsn(MethodWriter.getType(iterator.clazz).getOpcode(Opcodes.ILOAD), iterator.getSlot()); - writer.invokeInterface(ITERATOR_TYPE, ITERATOR_HASNEXT); - writer.ifZCmp(MethodWriter.EQ, end); + methodWriter.visitVarInsn(MethodWriter.getType(iterator.clazz).getOpcode(Opcodes.ILOAD), iterator.getSlot()); + methodWriter.invokeInterface(ITERATOR_TYPE, ITERATOR_HASNEXT); + methodWriter.ifZCmp(MethodWriter.EQ, end); - writer.visitVarInsn(MethodWriter.getType(iterator.clazz).getOpcode(Opcodes.ILOAD), iterator.getSlot()); - writer.invokeInterface(ITERATOR_TYPE, ITERATOR_NEXT); - writer.writeCast(cast); - writer.visitVarInsn(MethodWriter.getType(variable.clazz).getOpcode(Opcodes.ISTORE), variable.getSlot()); + methodWriter.visitVarInsn(MethodWriter.getType(iterator.clazz).getOpcode(Opcodes.ILOAD), iterator.getSlot()); + methodWriter.invokeInterface(ITERATOR_TYPE, ITERATOR_NEXT); + methodWriter.writeCast(cast); + methodWriter.visitVarInsn(MethodWriter.getType(variable.clazz).getOpcode(Opcodes.ISTORE), variable.getSlot()); if (loopCounter != null) { - writer.writeLoopCounter(loopCounter.getSlot(), statementCount, location); + methodWriter.writeLoopCounter(loopCounter.getSlot(), statementCount, location); } block.continu = begin; block.brake = end; - block.write(writer, globals); + block.write(classWriter, methodWriter, globals); - writer.goTo(begin); - writer.mark(end); + methodWriter.goTo(begin); + methodWriter.mark(end); } @Override diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SThrow.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SThrow.java index a5e1c094b0cdf..79ed5e3a7246e 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SThrow.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SThrow.java @@ -19,6 +19,7 @@ package org.elasticsearch.painless.node; +import org.elasticsearch.painless.ClassWriter; import org.elasticsearch.painless.CompilerSettings; import org.elasticsearch.painless.Globals; import org.elasticsearch.painless.Locals; @@ -64,10 +65,10 @@ void analyze(Locals locals) { } @Override - void write(MethodWriter writer, Globals globals) { - writer.writeStatementOffset(location); - expression.write(writer, globals); - writer.throwException(); + void write(ClassWriter classWriter, MethodWriter methodWriter, Globals globals) { + methodWriter.writeStatementOffset(location); + expression.write(classWriter, methodWriter, globals); + methodWriter.throwException(); } @Override diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/STry.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/STry.java index 16f97f094365e..44705000b5bde 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/STry.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/STry.java @@ -19,6 +19,7 @@ package org.elasticsearch.painless.node; +import org.elasticsearch.painless.ClassWriter; import org.elasticsearch.painless.CompilerSettings; import org.elasticsearch.painless.Globals; import org.elasticsearch.painless.Locals; @@ -108,34 +109,34 @@ void analyze(Locals locals) { } @Override - void write(MethodWriter writer, Globals globals) { - writer.writeStatementOffset(location); + void write(ClassWriter classWriter, MethodWriter methodWriter, Globals globals) { + methodWriter.writeStatementOffset(location); Label begin = new Label(); Label end = new Label(); Label exception = new Label(); - writer.mark(begin); + methodWriter.mark(begin); block.continu = continu; block.brake = brake; - block.write(writer, globals); + block.write(classWriter, methodWriter, globals); if (!block.allEscape) { - writer.goTo(exception); + methodWriter.goTo(exception); } - writer.mark(end); + methodWriter.mark(end); for (SCatch catc : catches) { catc.begin = begin; catc.end = end; catc.exception = catches.size() > 1 ? exception : null; - catc.write(writer, globals); + catc.write(classWriter, methodWriter, globals); } if (!block.allEscape || catches.size() > 1) { - writer.mark(exception); + methodWriter.mark(exception); } } diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SWhile.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SWhile.java index 822107100886d..ec237a0f8b657 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SWhile.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SWhile.java @@ -19,6 +19,7 @@ package org.elasticsearch.painless.node; +import org.elasticsearch.painless.ClassWriter; import org.elasticsearch.painless.CompilerSettings; import org.elasticsearch.painless.Globals; import org.elasticsearch.painless.Locals; @@ -110,38 +111,38 @@ void analyze(Locals locals) { } @Override - void write(MethodWriter writer, Globals globals) { - writer.writeStatementOffset(location); + void write(ClassWriter classWriter, MethodWriter methodWriter, Globals globals) { + methodWriter.writeStatementOffset(location); Label begin = new Label(); Label end = new Label(); - writer.mark(begin); + methodWriter.mark(begin); if (!continuous) { - condition.write(writer, globals); - writer.ifZCmp(Opcodes.IFEQ, end); + condition.write(classWriter, methodWriter, globals); + methodWriter.ifZCmp(Opcodes.IFEQ, end); } if (block != null) { if (loopCounter != null) { - writer.writeLoopCounter(loopCounter.getSlot(), Math.max(1, block.statementCount), location); + methodWriter.writeLoopCounter(loopCounter.getSlot(), Math.max(1, block.statementCount), location); } block.continu = begin; block.brake = end; - block.write(writer, globals); + block.write(classWriter, methodWriter, globals); } else { if (loopCounter != null) { - writer.writeLoopCounter(loopCounter.getSlot(), 1, location); + methodWriter.writeLoopCounter(loopCounter.getSlot(), 1, location); } } if (block == null || !block.allEscape) { - writer.goTo(begin); + methodWriter.goTo(begin); } - writer.mark(end); + methodWriter.mark(end); } @Override