src/jdk/nashorn/internal/runtime/SetMethodCreator.java
Print this page
rev 742 : 8029667: Prototype linking is incorrect
Reviewed-by: jlaskey, sundar
rev 755 : 8035948: Redesign property listeners for shared classes
Reviewed-by: sundar, lagergren
rev 758 : 8021350: Share script classes between threads/globals within context
Reviewed-by: lagergren, sundar
rev 760 : 8037400: Remove getInitialMap getters and GlobalObject interface
Reviewed-by: lagergren, jlaskey, attila
@@ -29,11 +29,10 @@
import static jdk.nashorn.internal.lookup.Lookup.MH;
import java.lang.invoke.MethodHandle;
import jdk.internal.dynalink.CallSiteDescriptor;
import jdk.internal.dynalink.linker.GuardedInvocation;
-import jdk.nashorn.internal.codegen.ObjectClassGenerator;
import jdk.nashorn.internal.lookup.Lookup;
import jdk.nashorn.internal.runtime.linker.NashornCallSiteDescriptor;
import jdk.nashorn.internal.runtime.linker.NashornGuards;
@@ -78,11 +77,11 @@
GuardedInvocation createGuardedInvocation() {
return createSetMethod().createGuardedInvocation();
}
/**
- * This class encapsulates the results of looking up a setter method; it's basically a triple of a method hanle,
+ * This class encapsulates the results of looking up a setter method; it's basically a triple of a method handle,
* a Property object, and flags for invocation.
*
*/
private class SetMethod {
private final MethodHandle methodHandle;
@@ -102,25 +101,13 @@
/**
* Composes from its components an actual guarded invocation that represents the dynamic setter method for the property.
* @return the composed guarded invocation that represents the dynamic setter method for the property.
*/
GuardedInvocation createGuardedInvocation() {
- return new GuardedInvocation(methodHandle, getGuard());
+ return new GuardedInvocation(methodHandle, NashornGuards.getGuard(sobj, property, desc));
}
- private MethodHandle getGuard() {
- return needsNoGuard() ? null : NashornGuards.getMapGuard(getMap());
- }
-
- private boolean needsNoGuard() {
- return NashornCallSiteDescriptor.isFastScope(desc) &&
- (ObjectClassGenerator.OBJECT_FIELDS_ONLY || isPropertyTypeStable());
- }
-
- private boolean isPropertyTypeStable() {
- return property == null || !property.canChangeType();
- }
}
private SetMethod createSetMethod() {
if (find != null) {
return createExistingPropertySetter();
@@ -149,28 +136,30 @@
final MethodHandle methodHandle = find.getSetter(type, NashornCallSiteDescriptor.isStrict(desc));
assert methodHandle != null;
assert property != null;
- final ScriptObject prototype = find.getOwner();
final MethodHandle boundHandle;
- if (!property.hasSetterFunction(prototype) && find.isInherited()) {
- boundHandle = ScriptObject.bindTo(methodHandle, prototype);
+ if (!property.hasSetterFunction(find.getOwner()) && find.isInherited()) {
+ boundHandle = ScriptObject.addProtoFilter(methodHandle, find.getProtoChainLength());
} else {
boundHandle = methodHandle;
}
return new SetMethod(boundHandle, property);
}
private SetMethod createGlobalPropertySetter() {
- final ScriptObject global = Context.getGlobalTrusted();
- return new SetMethod(ScriptObject.bindTo(global.addSpill(getName()), global), null);
+ final ScriptObject global = Context.getGlobal();
+ return new SetMethod(MH.filterArguments(global.addSpill(getName()), 0, ScriptObject.GLOBALFILTER), null);
}
private SetMethod createNewPropertySetter() {
final SetMethod sm = map.getFieldCount() < map.getFieldMaximum() ? createNewFieldSetter() : createNewSpillPropertySetter();
- sobj.notifyPropertyAdded(sobj, sm.property);
+ final PropertyListeners listeners = map.getListeners();
+ if (listeners != null) {
+ listeners.propertyAdded(sm.property);
+ }
return sm;
}
private SetMethod createNewFieldSetter() {
final PropertyMap oldMap = getMap();