Package org.codehaus.groovy.classgen.asm
Class OptimizingStatementWriter
java.lang.Object
org.codehaus.groovy.classgen.asm.StatementWriter
org.codehaus.groovy.classgen.asm.OptimizingStatementWriter
A
StatementWriter that emits optimized fast-path bytecode for statements
involving integer (and other primitive) operations. When type guards confirm that
the operands have their original (unboxed) types, the fast path is taken;
otherwise execution falls back to the standard dynamic-dispatch slow path.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classMarker metadata used to skip optimization analysis for a class node.static classStores optimization metadata collected for a statement or expression. -
Field Summary
Fields inherited from class org.codehaus.groovy.classgen.asm.StatementWriter
controller -
Constructor Summary
ConstructorsConstructorDescriptionOptimizingStatementWriter(WriterController controller) Creates an optimizing statement writer backed by the given controller. -
Method Summary
Modifier and TypeMethodDescriptionstatic voidsetNodeMeta(TypeChooser chooser, ClassNode classNode) Populates optimization metadata for the supplied class.voidwriteBlockStatement(BlockStatement statement) Generates bytecode for a block statement by visiting each contained statement.voidwriteDoWhileLoop(DoWhileStatement statement) Generates bytecode for a do-while loop.voidwriteExpressionStatement(ExpressionStatement statement) Generates bytecode for an expression statement.protected voidwriteForInLoop(ForStatement statement) Generates bytecode for a for-in loop by callingiterator()on the collection expression and delegating loop control toStatementWriter.writeForInLoopControlAndBlock(org.codehaus.groovy.ast.stmt.ForStatement).protected voidwriteForLoopWithClosureList(ForStatement statement) Generates bytecode for a C-stylefor(init; cond; incr)loop.voidwriteIfElse(IfStatement statement) Generates bytecode for an if/else statement.protected voidwriteIteratorHasNext(org.objectweb.asm.MethodVisitor mv) Emits theIterator.hasNext()call via the given visitor.protected voidwriteIteratorNext(org.objectweb.asm.MethodVisitor mv) Emits theIterator.next()call via the given visitor.voidwriteReturn(ReturnStatement statement) Generates bytecode for a return statement.voidwriteWhileLoop(WhileStatement statement) Generates bytecode for a while loop.Methods inherited from class org.codehaus.groovy.classgen.asm.StatementWriter
defineLoopIndexVariable, writeAssert, writeBreak, writeContinue, writeForInLoopControlAndBlock, writeForStatement, writeLoopBackEdge, writeStatementLabel, writeSwitch, writeSynchronized, writeThrow, writeTryCatchFinally
-
Constructor Details
-
OptimizingStatementWriter
Creates an optimizing statement writer backed by the given controller.- Parameters:
controller- the writer controller for the current compilation
-
-
Method Details
-
writeBlockStatement
Generates bytecode for a block statement by visiting each contained statement. Pushes the block's variable scope, emits the statements, and pops afterward. Named labels on the block create a breakable region so thatbreak labelwithin the block jumps to the end of it.- Overrides:
writeBlockStatementin classStatementWriter- Parameters:
statement- the block statement to compile
-
writeDoWhileLoop
Generates bytecode for a do-while loop.- Overrides:
writeDoWhileLoopin classStatementWriter- Parameters:
statement- the do-while statement to compile
-
writeIteratorHasNext
protected void writeIteratorHasNext(org.objectweb.asm.MethodVisitor mv) Emits theIterator.hasNext()call via the given visitor. Overrideable so subclasses can substitute a specialized or inlined variant.- Overrides:
writeIteratorHasNextin classStatementWriter- Parameters:
mv- the method visitor to write to
-
writeIteratorNext
protected void writeIteratorNext(org.objectweb.asm.MethodVisitor mv) Emits theIterator.next()call via the given visitor. Overrideable so subclasses can substitute a specialized or inlined variant.- Overrides:
writeIteratorNextin classStatementWriter- Parameters:
mv- the method visitor to write to
-
writeForInLoop
Generates bytecode for a for-in loop by callingiterator()on the collection expression and delegating loop control toStatementWriter.writeForInLoopControlAndBlock(org.codehaus.groovy.ast.stmt.ForStatement).- Overrides:
writeForInLoopin classStatementWriter- Parameters:
statement- the for-in statement to compile
-
writeForLoopWithClosureList
Generates bytecode for a C-stylefor(init; cond; incr)loop. The collection expression is aClosureListExpressionwhose middle element is the boolean condition, lower elements are initializers, and upper elements are incrementors.- Overrides:
writeForLoopWithClosureListin classStatementWriter- Parameters:
statement- the for statement with aClosureListExpressioncollection
-
writeWhileLoop
Generates bytecode for a while loop.- Overrides:
writeWhileLoopin classStatementWriter- Parameters:
statement- the while statement to compile
-
writeIfElse
Generates bytecode for an if/else statement.- Overrides:
writeIfElsein classStatementWriter- Parameters:
statement- the if statement to compile
-
writeReturn
Generates bytecode for a return statement. For void methods emitsRETURNafter applying any finally blocks. For value-returning methods evaluates the expression, casts it to the declared return type, and emits the appropriate typed return instruction.- Overrides:
writeReturnin classStatementWriter- Parameters:
statement- the return statement to compile
-
writeExpressionStatement
Generates bytecode for an expression statement. Evaluates the expression and discards any value left on the operand stack. Marks method-call and binary expressions so that unused return values are elided rather than boxed.- Overrides:
writeExpressionStatementin classStatementWriter- Parameters:
statement- the expression statement to compile
-
setNodeMeta
Populates optimization metadata for the supplied class.- Parameters:
chooser- the type chooser used during analysisclassNode- the class to annotate
-