94 import jdk.internal.dynalink.linker.LinkerServices; |
94 import jdk.internal.dynalink.linker.LinkerServices; |
95 import jdk.internal.dynalink.support.CallSiteDescriptorFactory; |
95 import jdk.internal.dynalink.support.CallSiteDescriptorFactory; |
96 import jdk.internal.dynalink.support.LinkRequestImpl; |
96 import jdk.internal.dynalink.support.LinkRequestImpl; |
97 import jdk.internal.dynalink.support.Lookup; |
97 import jdk.internal.dynalink.support.Lookup; |
98 import jdk.internal.dynalink.support.RuntimeContextLinkRequestImpl; |
98 import jdk.internal.dynalink.support.RuntimeContextLinkRequestImpl; |
99 |
|
100 |
99 |
101 /** |
100 /** |
102 * The linker for {@link RelinkableCallSite} objects. Users of it (scripting frameworks and language runtimes) have to |
101 * The linker for {@link RelinkableCallSite} objects. Users of it (scripting frameworks and language runtimes) have to |
103 * create a linker using the {@link DynamicLinkerFactory} and invoke its link method from the invokedynamic bootstrap |
102 * create a linker using the {@link DynamicLinkerFactory} and invoke its link method from the invokedynamic bootstrap |
104 * methods to set the target of all the call sites in the code they generate. Usual usage would be to create one class |
103 * methods to set the target of all the call sites in the code they generate. Usual usage would be to create one class |
244 final MethodHandle guard = guardedInvocation.getGuard(); |
243 final MethodHandle guard = guardedInvocation.getGuard(); |
245 guardedInvocation = guardedInvocation.dropArguments(1, prefix); |
244 guardedInvocation = guardedInvocation.dropArguments(1, prefix); |
246 } |
245 } |
247 } |
246 } |
248 |
247 |
249 if(unstableDetectionEnabled && relinkCount <= unstableRelinkThreshold && relinkCount++ == unstableRelinkThreshold) { |
248 int newRelinkCount = relinkCount; |
250 // Note that we'll increase the relinkCount until threshold+1 and not increase it beyond that. Threshold+1 |
249 // Note that the short-circuited "&&" evaluation below ensures we'll increment the relinkCount until |
251 // is treated as a special value to signal that resetAndRelink has already executed once for the unstable |
250 // threshold + 1 but not beyond that. Threshold + 1 is treated as a special value to signal that resetAndRelink |
252 // call site; we only want the call site to throw away its current linkage once, when it transitions to |
251 // has already executed once for the unstable call site; we only want the call site to throw away its current |
253 // unstable. |
252 // linkage once, when it transitions to unstable. |
254 callSite.resetAndRelink(guardedInvocation, createRelinkAndInvokeMethod(callSite, relinkCount)); |
253 if(unstableDetectionEnabled && newRelinkCount <= unstableRelinkThreshold && newRelinkCount++ == unstableRelinkThreshold) { |
|
254 callSite.resetAndRelink(guardedInvocation, createRelinkAndInvokeMethod(callSite, newRelinkCount)); |
255 } else { |
255 } else { |
256 callSite.relink(guardedInvocation, createRelinkAndInvokeMethod(callSite, relinkCount)); |
256 callSite.relink(guardedInvocation, createRelinkAndInvokeMethod(callSite, newRelinkCount)); |
257 } |
257 } |
258 if(syncOnRelink) { |
258 if(syncOnRelink) { |
259 MutableCallSite.syncAll(new MutableCallSite[] { (MutableCallSite)callSite }); |
259 MutableCallSite.syncAll(new MutableCallSite[] { (MutableCallSite)callSite }); |
260 } |
260 } |
261 return guardedInvocation.getInvocation(); |
261 return guardedInvocation.getInvocation(); |