Package org.codehaus.groovy.classgen.asm
Class CallSiteWriter
java.lang.Object
org.codehaus.groovy.classgen.asm.CallSiteWriter
- Direct Known Subclasses:
IndyCallSiteWriter,StaticTypesCallSiteWriter
Bytecode writer for classic (non-
invokedynamic) call sites.
Non-public API used by AsmClassGenerator. Do not use this class
in application code. Groovy 6 defaults to invokedynamic
(IndyCallSiteWriter);
this writer is selected only when indy is disabled. The generated
bytecode references org.codehaus.groovy.runtime.callsite.*, which
lives in the optional groovy-callsite module — that module must be
on the classpath both to emit and to execute such classes
(WriterController fails fast if it is missing when indy is off).
- See Also:
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionCreates a call site writer with the given controller. -
Method Summary
Modifier and TypeMethodDescriptionvoidfallbackAttributeOrPropertySite(PropertyExpression expression, Expression objectExpression, String name, MethodCallerMultiAdapter adapter) Generates a fallback call for attribute or property access.voidGenerates the call site array field and accessor methods.Returns the list of call site names.booleanChecks if any call sites have been used.booleanReturns true if a call-site array loading prologue has been emitted for at least one method of the current class.voidmakeCallSite(Expression receiver, String message, Expression arguments, boolean safe, boolean implicitThis, boolean callCurrent, boolean callStatic) Generates a general method call through the call site infrastructure.voidGenerates bytecode to initialize the call site array field to null.voidmakeGetPropertySite(Expression receiver, String methodName, boolean safe, boolean implicitThis) Generates a general getProperty call.voidmakeGroovyObjectGetPropertySite(Expression receiver, String methodName, boolean safe, boolean implicitThis) Generates a GroovyObject getProperty call.voidmakeSetPropertySite(PropertyExpression expression, Expression objectExpression, String name, MethodCallerMultiAdapter adapter, boolean groovyObject) Emits a property-write site (GROOVY-12138).final voidmakeSingleArgumentCall(Expression receiver, String message, Expression arguments) Generates a single-argument method call.voidmakeSingleArgumentCall(Expression receiver, String message, Expression arguments, boolean safe) Generates a single-argument method call with optional safe navigation.voidGenerates bytecode to load the call site array into a local variable.voidprepareCallSite(String message) Prepares a call-site entry for the named method on the bytecode operand stack, loading the call-site array and selecting the slot formessage.protected voidprepareSiteAndReceiver(Expression receiver, String methodName, boolean implicitThis, boolean lhs) Generates bytecode to prepare the call site and receiver for a method call.protected voidVisits an argument expression and ensures it is boxed.
-
Field Details
-
CONSTRUCTOR
Sentinel name for constructor calls.- See Also:
-
-
Constructor Details
-
CallSiteWriter
Creates a call site writer with the given controller.- Parameters:
wc- the writer controller
-
-
Method Details
-
makeSiteEntry
public void makeSiteEntry()Generates bytecode to load the call site array into a local variable. -
isPrologueEmitted
public boolean isPrologueEmitted()Returns true if a call-site array loading prologue has been emitted for at least one method of the current class. -
generateCallSiteArray
public void generateCallSiteArray()Generates the call site array field and accessor methods. -
prepareCallSite
Prepares a call-site entry for the named method on the bytecode operand stack, loading the call-site array and selecting the slot formessage.- Parameters:
message- the method name for which to prepare the call site
-
prepareSiteAndReceiver
protected void prepareSiteAndReceiver(Expression receiver, String methodName, boolean implicitThis, boolean lhs) Generates bytecode to prepare the call site and receiver for a method call.- Parameters:
receiver- the receiver expressionmethodName- the method nameimplicitThis- whether the receiver is implicit 'this'lhs- whether this is on the left-hand side of an assignment
-
visitBoxedArgument
Visits an argument expression and ensures it is boxed.- Parameters:
exp- the argument expression
-
makeSingleArgumentCall
Generates a single-argument method call.- Parameters:
receiver- the receiver expressionmessage- the method namearguments- the argument expression
-
makeSingleArgumentCall
public void makeSingleArgumentCall(Expression receiver, String message, Expression arguments, boolean safe) Generates a single-argument method call with optional safe navigation.- Parameters:
receiver- the receiver expressionmessage- the method namearguments- the argument expressionsafe- whether to use safe navigation
-
makeGroovyObjectGetPropertySite
public void makeGroovyObjectGetPropertySite(Expression receiver, String methodName, boolean safe, boolean implicitThis) Generates a GroovyObject getProperty call.- Parameters:
receiver- the receiver expressionmethodName- the property namesafe- whether to use safe navigationimplicitThis- whether the receiver is implicit 'this'
-
makeGetPropertySite
public void makeGetPropertySite(Expression receiver, String methodName, boolean safe, boolean implicitThis) Generates a general getProperty call.- Parameters:
receiver- the receiver expressionmethodName- the property namesafe- whether to use safe navigationimplicitThis- whether the receiver is implicit 'this'
-
makeCallSite
public void makeCallSite(Expression receiver, String message, Expression arguments, boolean safe, boolean implicitThis, boolean callCurrent, boolean callStatic) Generates a general method call through the call site infrastructure.- Parameters:
receiver- the receiver expressionmessage- the method namearguments- the arguments expressionsafe- whether to use safe navigationimplicitThis- whether the receiver is implicit 'this'callCurrent- whether to call on the current objectcallStatic- whether this is a static method call
-
getCallSites
Returns the list of call site names.- Returns:
- the call site names
-
makeCallSiteArrayInitializer
public void makeCallSiteArrayInitializer()Generates bytecode to initialize the call site array field to null. -
hasCallSiteUse
public boolean hasCallSiteUse()Checks if any call sites have been used.- Returns:
- true if call sites have been used
-
fallbackAttributeOrPropertySite
public void fallbackAttributeOrPropertySite(PropertyExpression expression, Expression objectExpression, String name, MethodCallerMultiAdapter adapter) Generates a fallback call for attribute or property access.- Parameters:
expression- the property expressionobjectExpression- the object expressionname- the property nameadapter- the method caller adapter
-
makeSetPropertySite
public void makeSetPropertySite(PropertyExpression expression, Expression objectExpression, String name, MethodCallerMultiAdapter adapter, boolean groovyObject) Emits a property-write site (GROOVY-12138). The assigned value is already on the operand stack. The default implementation is the classicScriptBytecodeAdapteradapter call; the indy writer may override this to emit aninvokedynamicsetPropertycall site.- Parameters:
expression- the property expression being assignedobjectExpression- the receiver expressionname- the property nameadapter- the classic set adapter used for the default pathgroovyObject- whether the receiver is statically known to be aGroovyObject
-