Top Description Inners Fields Constructors Methods
jdk.internal.org.objectweb.asm.commons

public Class JSRInlinerAdapter

extends MethodNode
implements Opcodes
Class Inheritance
All Implemented Interfaces
jdk.internal.org.objectweb.asm.Opcodes
Imports
java.util.AbstractMap, .ArrayList, .BitSet, .HashMap, .LinkedList, .List, .Map, .Set, jdk.internal.org.objectweb.asm.Label, .MethodVisitor, .Opcodes, jdk.internal.org.objectweb.asm.tree.AbstractInsnNode, .InsnList, .InsnNode, .JumpInsnNode, .LabelNode, .LocalVariableNode, .LookupSwitchInsnNode, .MethodNode, .TableSwitchInsnNode, .TryCatchBlockNode

A jdk.internal.org.objectweb.asm.MethodVisitor that removes JSR instructions and inlines the referenced subroutines.
Author
Niko Matsakis

Nested and Inner Type Summary

Modifier and TypeClass and Description
private class
JSRInlinerAdapter.Instantiation

An instantiation of a subroutine.

Field Summary

Modifier and TypeField and Description
private final BitSet
mainSubroutineInsns

The instructions that belong to the main "subroutine".

pack-priv final BitSet
sharedSubroutineInsns

The instructions that belong to more that one subroutine.

private final Map<LabelNode, BitSet>
subroutinesInsns

The instructions that belong to each subroutine.

Inherited from jdk.internal.org.objectweb.asm.tree.MethodNode:
accessannotationDefaultattrsdescexceptionsinstructionsinvisibleAnnotableParameterCountinvisibleAnnotationsinvisibleLocalVariableAnnotationsinvisibleParameterAnnotationsinvisibleTypeAnnotationslocalVariablesmaxLocalsmaxStacknameparameterssignaturetryCatchBlocksvisibleAnnotableParameterCountvisibleAnnotationsvisibleLocalVariableAnnotationsvisibleParameterAnnotationsvisibleTypeAnnotations

Constructor Summary

AccessConstructor and Description
public
JSRInlinerAdapter(final MethodVisitor
the method visitor to send the resulting inlined method code to, or null.
methodVisitor
,
final int
the method's access flags.
access
,
final String
the method's name.
name
,
final String
the method's descriptor.
descriptor
,
final String
the method's signature. May be null.
signature
,
final String[]
the internal names of the method's exception classes. May be null.
exceptions
)

Constructs a new JSRInlinerAdapter.

protected
JSRInlinerAdapter(final int
the ASM API version implemented by this visitor. Must be one of the ASMx values in Opcodes.
api
,
final MethodVisitor
the method visitor to send the resulting inlined method code to, or null.
methodVisitor
,
final int
the method's access flags (see Opcodes). This parameter also indicates if the method is synthetic and/or deprecated.
access
,
final String
the method's name.
name
,
final String
the method's descriptor.
descriptor
,
final String
the method's signature. May be null.
signature
,
final String[]
the internal names of the method's exception classes. May be null.
exceptions
)

Constructs a new JSRInlinerAdapter.

Method Summary

Modifier and TypeMethod and Description
private void
emitCode()

Creates the new instructions, inlining each instantiation of each subroutine until the code is fully elaborated.

private void
emitInstantiation(final JSRInlinerAdapter.Instantiation
the instantiation that must be performed.
instantiation
,
final List<JSRInlinerAdapter.Instantiation>
list of the instantiations that remain to be done.
worklist
,
final InsnList
the instruction list to which the instantiated code must be appended.
newInstructions
,
final List<TryCatchBlockNode>
the exception handler list to which the instantiated handlers must be appended.
newTryCatchBlocks
,
final List<LocalVariableNode>
the local variables list to which the instantiated local variables must be appended.
newLocalVariables
)

Emits an instantiation of a subroutine, specified by instantiation.

private void
findReachableInsns(final int
the index of an instruction of the subroutine.
insnIndex
,
final BitSet
where the indices of the instructions of the subroutine must be stored.
subroutineInsns
,
final BitSet
the indices of the instructions that have been visited so far (including in previous calls to this method). This bitset is updated by this method each time a new instruction is visited. It is used to make sure each instruction is visited at most once.
visitedInsns
)

Finds the instructions that are reachable from the given instruction, without following any JSR instruction nor any exception handler.

private void
findSubroutineInsns(final int
the index of the first instruction of the subroutine.
startInsnIndex
,
final BitSet
where the indices of the instructions of the subroutine must be stored.
subroutineInsns
,
final BitSet
the indices of the instructions that have been visited so far (including in previous calls to this method). This bitset is updated by this method each time a new instruction is visited. It is used to make sure each instruction is visited at most once.
visitedInsns
)

Finds the instructions that belong to the subroutine starting at the given instruction index.

private void
findSubroutinesInsns()

Determines, for each instruction, to which subroutine(s) it belongs.

public void
visitEnd()

Overrides jdk.internal.org.objectweb.asm.tree.MethodNode.visitEnd.

Visits the end of the method.
public void
visitJumpInsn(final int
the opcode of the type instruction to be visited. This opcode is either IFEQ, IFNE, IFLT, IFGE, IFGT, IFLE, IF_ICMPEQ, IF_ICMPNE, IF_ICMPLT, IF_ICMPGE, IF_ICMPGT, IF_ICMPLE, IF_ACMPEQ, IF_ACMPNE, GOTO, JSR, IFNULL or IFNONNULL.
opcode
,
final Label
the operand of the instruction to be visited. This operand is a label that designates the instruction to which the jump instruction may jump.
label
)

Overrides jdk.internal.org.objectweb.asm.tree.MethodNode.visitJumpInsn.

Visits a jump instruction.
Inherited from jdk.internal.org.objectweb.asm.tree.MethodNode:
acceptacceptcheckgetLabelNodevisitAnnotableParameterCountvisitAnnotationvisitAnnotationDefaultvisitAttributevisitCodevisitFieldInsnvisitFramevisitIincInsnvisitInsnvisitInsnAnnotationvisitIntInsnvisitInvokeDynamicInsnvisitLabelvisitLdcInsnvisitLineNumbervisitLocalVariablevisitLocalVariableAnnotationvisitLookupSwitchInsnvisitMaxsvisitMethodInsnvisitMultiANewArrayInsnvisitParametervisitParameterAnnotationvisitTableSwitchInsnvisitTryCatchAnnotationvisitTryCatchBlockvisitTypeAnnotationvisitTypeInsnvisitVarInsn

Field Detail

mainSubroutineInsnsback to summary
private final BitSet mainSubroutineInsns

The instructions that belong to the main "subroutine". Bit i is set iff instruction at index i belongs to this main "subroutine".

sharedSubroutineInsnsback to summary
pack-priv final BitSet sharedSubroutineInsns

The instructions that belong to more that one subroutine. Bit i is set iff instruction at index i belongs to more than one subroutine.

subroutinesInsnsback to summary
private final Map<LabelNode, BitSet> subroutinesInsns

The instructions that belong to each subroutine. For each label which is the target of a JSR instruction, bit i of the corresponding BitSet in this map is set iff instruction at index i belongs to this subroutine.

Constructor Detail

JSRInlinerAdapterback to summary
public JSRInlinerAdapter(final MethodVisitor methodVisitor, final int access, final String name, final String descriptor, final String signature, final String[] exceptions)

Constructs a new JSRInlinerAdapter. Subclasses must not use this constructor. Instead, they must use the JSRInlinerAdapter(int, MethodVisitor, int, String, String, String, String[]) version.

Parameters
methodVisitor:MethodVisitor

the method visitor to send the resulting inlined method code to, or null.

access:int

the method's access flags.

name:String

the method's name.

descriptor:String

the method's descriptor.

signature:String

the method's signature. May be null.

exceptions:String[]

the internal names of the method's exception classes. May be null.

Exceptions
IllegalStateException:
if a subclass calls this constructor.
JSRInlinerAdapterback to summary
protected JSRInlinerAdapter(final int api, final MethodVisitor methodVisitor, final int access, final String name, final String descriptor, final String signature, final String[] exceptions)

Constructs a new JSRInlinerAdapter.

Parameters
api:int

the ASM API version implemented by this visitor. Must be one of the ASMx values in Opcodes.

methodVisitor:MethodVisitor

the method visitor to send the resulting inlined method code to, or null.

access:int

the method's access flags (see Opcodes). This parameter also indicates if the method is synthetic and/or deprecated.

name:String

the method's name.

descriptor:String

the method's descriptor.

signature:String

the method's signature. May be null.

exceptions:String[]

the internal names of the method's exception classes. May be null.

Method Detail

emitCodeback to summary
private void emitCode()

Creates the new instructions, inlining each instantiation of each subroutine until the code is fully elaborated.

emitInstantiationback to summary
private void emitInstantiation(final JSRInlinerAdapter.Instantiation instantiation, final List<JSRInlinerAdapter.Instantiation> worklist, final InsnList newInstructions, final List<TryCatchBlockNode> newTryCatchBlocks, final List<LocalVariableNode> newLocalVariables)

Emits an instantiation of a subroutine, specified by instantiation. May add new instantiations that are invoked by this one to the worklist, and new try/catch blocks to newTryCatchBlocks.

Parameters
instantiation:JSRInlinerAdapter.Instantiation

the instantiation that must be performed.

worklist:List<JSRInlinerAdapter.Instantiation>

list of the instantiations that remain to be done.

newInstructions:InsnList

the instruction list to which the instantiated code must be appended.

newTryCatchBlocks:List<TryCatchBlockNode>

the exception handler list to which the instantiated handlers must be appended.

newLocalVariables:List<LocalVariableNode>

the local variables list to which the instantiated local variables must be appended.

findReachableInsnsback to summary
private void findReachableInsns(final int insnIndex, final BitSet subroutineInsns, final BitSet visitedInsns)

Finds the instructions that are reachable from the given instruction, without following any JSR instruction nor any exception handler. For this the control flow graph is visited with a depth first search.

Parameters
insnIndex:int

the index of an instruction of the subroutine.

subroutineInsns:BitSet

where the indices of the instructions of the subroutine must be stored.

visitedInsns:BitSet

the indices of the instructions that have been visited so far (including in previous calls to this method). This bitset is updated by this method each time a new instruction is visited. It is used to make sure each instruction is visited at most once.

findSubroutineInsnsback to summary
private void findSubroutineInsns(final int startInsnIndex, final BitSet subroutineInsns, final BitSet visitedInsns)

Finds the instructions that belong to the subroutine starting at the given instruction index. For this the control flow graph is visited with a depth first search (this includes the normal control flow and the exception handlers).

Parameters
startInsnIndex:int

the index of the first instruction of the subroutine.

subroutineInsns:BitSet

where the indices of the instructions of the subroutine must be stored.

visitedInsns:BitSet

the indices of the instructions that have been visited so far (including in previous calls to this method). This bitset is updated by this method each time a new instruction is visited. It is used to make sure each instruction is visited at most once.

findSubroutinesInsnsback to summary
private void findSubroutinesInsns()

Determines, for each instruction, to which subroutine(s) it belongs.

visitEndback to summary
public void visitEnd()

Overrides jdk.internal.org.objectweb.asm.tree.MethodNode.visitEnd.

Doc from jdk.internal.org.objectweb.asm.MethodVisitor.visitEnd.

Visits the end of the method. This method, which is the last one to be called, is used to inform the visitor that all the annotations and attributes of the method have been visited.

Annotations
@Override
visitJumpInsnback to summary
public void visitJumpInsn(final int opcode, final Label label)

Overrides jdk.internal.org.objectweb.asm.tree.MethodNode.visitJumpInsn.

Doc from jdk.internal.org.objectweb.asm.MethodVisitor.visitJumpInsn.

Visits a jump instruction. A jump instruction is an instruction that may jump to another instruction.

Parameters
opcode:int

the opcode of the type instruction to be visited. This opcode is either IFEQ, IFNE, IFLT, IFGE, IFGT, IFLE, IF_ICMPEQ, IF_ICMPNE, IF_ICMPLT, IF_ICMPGE, IF_ICMPGT, IF_ICMPLE, IF_ACMPEQ, IF_ACMPNE, GOTO, JSR, IFNULL or IFNONNULL.

label:Label

the operand of the instruction to be visited. This operand is a label that designates the instruction to which the jump instruction may jump.

Annotations
@Override
jdk.internal.org.objectweb.asm.commons back to summary

private Class JSRInlinerAdapter.Instantiation

extends AbstractMap<LabelNode, LabelNode>
Class Inheritance

An instantiation of a subroutine.

Field Summary

Modifier and TypeField and Description
pack-priv final Map<LabelNode, LabelNode>
clonedLabels

A map from labels from the original code to labels pointing at code specific to this instantiation, for use in remapping try/catch blocks, as well as jumps.

pack-priv final JSRInlinerAdapter.Instantiation
parent

The instantiation from which this one was created (or null for the instantiation of the main "subroutine").

pack-priv final LabelNode
returnLabel

The return label for this instantiation, to which all original returns will be mapped.

pack-priv final BitSet
subroutineInsns

The original instructions that belong to the subroutine which is instantiated.

Constructor Summary

AccessConstructor and Description
pack-priv
Instantiation(final JSRInlinerAdapter.Instantiation parent, final BitSet subroutineInsns)

Method Summary

Modifier and TypeMethod and Description
public Set<Map.Entry<LabelNode, LabelNode>>
entrySet()

Implements abstract java.util.AbstractMap.entrySet.

Implements java.util.Map.entrySet.

Returns a Set view of the mappings contained in this map.
public boolean
equals(final Object
object to be compared for equality with this map
other
)

Overrides java.util.AbstractMap.equals.

Implements java.util.Map.equals.

Compares the specified object with this map for equality.
pack-priv JSRInlinerAdapter.Instantiation

Returns:

the "owner" of a particular instruction relative to this instantiation.
findOwner
(final int
the index of an instruction in the original code.
insnIndex
)

Returns the "owner" of a particular instruction relative to this instantiation: the owner refers to the Instantiation which will emit the version of this instruction that we will execute.

public LabelNode
get(final Object
the key whose associated value is to be returned
key
)

Overrides java.util.AbstractMap.get.

Implements java.util.Map.get.

Returns the value to which the specified key is mapped, or null if this map contains no mapping for the key.
pack-priv LabelNode

Returns:

a clone of the given label for use by a try/catch block or a variable annotation in the inlined code.
getClonedLabel
(final LabelNode
a label of the original code.
labelNode
)

Returns the clone of the given original label that is appropriate for use by a try/catch block or a variable annotation.

pack-priv LabelNode

Returns:

a clone of the given label for use in a jump instruction in the inlined code.
getClonedLabelForJumpInsn
(final LabelNode
a label of the original code.
labelNode
)

Returns the clone of the given original label that is appropriate for use in a jump instruction.

public int
hashCode()

Overrides java.util.AbstractMap.hashCode.

Implements java.util.Map.hashCode.

Returns the hash code value for this map.
Inherited from java.util.AbstractMap:
clearclonecontainsKeycontainsValueisEmptykeySetputputAllremovesizetoStringvalues

Field Detail

clonedLabelsback to summary
pack-priv final Map<LabelNode, LabelNode> clonedLabels

A map from labels from the original code to labels pointing at code specific to this instantiation, for use in remapping try/catch blocks, as well as jumps.

Note that in the presence of instructions belonging to several subroutines, we map the target label of a GOTO to the label used by the oldest instantiation (parent instantiations are older than their children). This avoids code duplication during inlining in most cases.

parentback to summary
pack-priv final JSRInlinerAdapter.Instantiation parent

The instantiation from which this one was created (or null for the instantiation of the main "subroutine").

returnLabelback to summary
pack-priv final LabelNode returnLabel

The return label for this instantiation, to which all original returns will be mapped.

subroutineInsnsback to summary
pack-priv final BitSet subroutineInsns

The original instructions that belong to the subroutine which is instantiated. Bit i is set iff instruction at index i belongs to this subroutine.

Constructor Detail

Instantiationback to summary
pack-priv Instantiation(final JSRInlinerAdapter.Instantiation parent, final BitSet subroutineInsns)

Method Detail

entrySetback to summary
public Set<Map.Entry<LabelNode, LabelNode>> entrySet()

Implements abstract java.util.AbstractMap.entrySet.

Implements java.util.Map.entrySet.

Doc from java.util.Map.entrySet.

Returns a Set view of the mappings contained in this map. The set is backed by the map, so changes to the map are reflected in the set, and vice-versa. If the map is modified while an iteration over the set is in progress (except through the iterator's own remove operation, or through the setValue operation on a map entry returned by the iterator) the results of the iteration are undefined. The set supports element removal, which removes the corresponding mapping from the map, via the Iterator.remove, Set.remove, removeAll, retainAll and clear operations. It does not support the add or addAll operations.

Returns:Set<Map.Entry<LabelNode, LabelNode>>

a set view of the mappings contained in this map

Annotations
@Override
equalsback to summary
public boolean equals(final Object other)

Overrides java.util.AbstractMap.equals.

Implements java.util.Map.equals.

Doc from java.util.AbstractMap.equals.

Compares the specified object with this map for equality. Returns true if the given object is also a map and the two maps represent the same mappings. More formally, two maps m1 and m2 represent the same mappings if m1.entrySet().equals(m2.entrySet()). This ensures that the equals method works properly across different implementations of the Map interface.

Parameters
other:Object

object to be compared for equality with this map

Returns:boolean

true if the specified object is equal to this map

Annotations
@Override
findOwnerback to summary
pack-priv JSRInlinerAdapter.Instantiation findOwner(final int insnIndex)

Returns the "owner" of a particular instruction relative to this instantiation: the owner refers to the Instantiation which will emit the version of this instruction that we will execute.

Typically, the return value is either this or null. this indicates that this instantiation will generate the version of this instruction that we will execute, and null indicates that this instantiation never executes the given instruction.

Sometimes, however, an instruction can belong to multiple subroutines; this is called a shared instruction, and occurs when multiple subroutines branch to common points of control. In this case, the owner is the oldest instantiation which owns the instruction in question (parent instantiations are older than their children).

Parameters
insnIndex:int

the index of an instruction in the original code.

Returns:JSRInlinerAdapter.Instantiation

the "owner" of a particular instruction relative to this instantiation.

getback to summary
public LabelNode get(final Object key)

Overrides java.util.AbstractMap.get.

Implements java.util.Map.get.

Doc from java.util.AbstractMap.get.

Returns the value to which the specified key is mapped, or null if this map contains no mapping for the key.

More formally, if this map contains a mapping from a key k to a value v such that Objects.equals(key, k), then this method returns v; otherwise it returns null. (There can be at most one such mapping.)

If this map permits null values, then a return value of null does not necessarily indicate that the map contains no mapping for the key; it's also possible that the map explicitly maps the key to null. The containsKey operation may be used to distinguish these two cases.

Parameters
key:Object

Doc from java.util.Map.get.

the key whose associated value is to be returned

Returns:LabelNode

Doc from java.util.Map.get.

the value to which the specified key is mapped, or null if this map contains no mapping for the key

Annotations
@Override
getClonedLabelback to summary
pack-priv LabelNode getClonedLabel(final LabelNode labelNode)

Returns the clone of the given original label that is appropriate for use by a try/catch block or a variable annotation.

Parameters
labelNode:LabelNode

a label of the original code.

Returns:LabelNode

a clone of the given label for use by a try/catch block or a variable annotation in the inlined code.

getClonedLabelForJumpInsnback to summary
pack-priv LabelNode getClonedLabelForJumpInsn(final LabelNode labelNode)

Returns the clone of the given original label that is appropriate for use in a jump instruction.

Parameters
labelNode:LabelNode

a label of the original code.

Returns:LabelNode

a clone of the given label for use in a jump instruction in the inlined code.

hashCodeback to summary
public int hashCode()

Overrides java.util.AbstractMap.hashCode.

Implements java.util.Map.hashCode.

Doc from java.util.AbstractMap.hashCode.

Returns the hash code value for this map. The hash code of a map is defined to be the sum of the hash codes of each entry in the map's entrySet() view. This ensures that m1.equals(m2) implies that m1.hashCode()==m2.hashCode() for any two maps m1 and m2, as required by the general contract of Object#hashCode.

Returns:int

the hash code value for this map

Annotations
@Override