Re CallSite relinking
Howard Lovatt
howard.lovatt at gmail.com
Mon Mar 7 00:01:41 PST 2011
I have found the following class useful for something similar, don't
know if it will be of help:
/** A {@link MutableCallSite} that can be reset to its initial target. */
public static class ResetableCallSite extends MutableCallSite {
private MethodHandle reset = null;
/**
* Make a blank call site object with the given method type. An
default target method is
* supplied which will throw an IllegalStateException if called
(this is not the reset (initial)
* target, a call to setTarget is required to set the reset
(initial) target).
*
* @param type the base type of the method handles that this
call site can target
*
* @throws NullPointerException if the proposed type is null
*/
public ResetableCallSite( final MethodType type ) throws
NullPointerException { super( type ); }
/**
* Make a call site object with the given target.
*
* @param target the method handle which will be the initial
target of the call site and the
* memorized reset target
*
* @throws NullPointerException if the proposed target is null
*/
public ResetableCallSite( final MethodHandle target ) throws
NullPointerException {
super( target );
reset = target;
}
/**
* Sets the target and if it is the first call to setTarget also
memorizes the target for reset if it is the first target set.
*
* @param target the new target
*
* @throws NullPointerException if the proposed new target is null
* @throws WrongMethodTypeException if the proposed new target
has a method type that differs
* from the previous target
*/
@Override public void setTarget( final MethodHandle target )
throws NullPointerException, WrongMethodTypeException {
super.setTarget( target );
if ( reset == null ) { reset = target; }
}
/**
* Reset the target to its first value (may need a sync afterwards).
*
* @throws IllegalStateException if target not already set
*/
public void reset() throws IllegalStateException {
if ( reset == null ) {
throw new IllegalStateException( "Target not set, therfore
can't reset" );
}
super.setTarget( reset );
}
/**
* String representation including the reset handle.
*
* @return super.toString() + "[reset = " + toString( reset ) + "]"
*/
@Override public String toString() {
return super.toString() + "[reset = " + toString( reset ) + "]";
}
}
--
-- Howard.
More information about the mlvm-dev
mailing list