src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/codegen/SharedScopeCall.java

Print this page




 139 
 140         final MethodEmitter method = classEmitter.method(methodFlags, methodName, getStaticSignature());
 141         method.begin();
 142 
 143         // Load correct scope by calling getProto() on the scope argument as often as specified
 144         // by the second argument.
 145         final Label parentLoopStart = new Label("parent_loop_start");
 146         final Label parentLoopDone  = new Label("parent_loop_done");
 147         method.load(Type.OBJECT, 0);
 148         method.label(parentLoopStart);
 149         method.load(Type.INT, 1);
 150         method.iinc(1, -1);
 151         method.ifle(parentLoopDone);
 152         method.invoke(ScriptObject.GET_PROTO);
 153         method._goto(parentLoopStart);
 154         method.label(parentLoopDone);
 155 
 156         assert !isCall || valueType.isObject(); // Callables are always objects
 157         // If flags are optimistic, but we're doing a call, remove optimistic flags from the getter, as they obviously
 158         // only apply to the call.
 159         method.dynamicGet(valueType, symbol.getName(), isCall ? CodeGenerator.nonOptimisticFlags(flags) : flags, isCall);
 160 
 161         // If this is a get we're done, otherwise call the value as function.
 162         if (isCall) {
 163             method.convert(Type.OBJECT);
 164             // ScriptFunction will see CALLSITE_SCOPE and will bind scope accordingly.
 165             method.loadUndefined(Type.OBJECT);
 166             int slot = 2;
 167             for (final Type type : paramTypes) {
 168                 method.load(type, slot);
 169                 slot += type.getSlots();
 170             }
 171             // Shared scope calls disabled in optimistic world. TODO is this right?
 172             method.dynamicCall(returnType, 2 + paramTypes.length, flags);
 173         }
 174 
 175         method._return(returnType);
 176         method.end();
 177     }
 178 
 179     private String getStaticSignature() {


 139 
 140         final MethodEmitter method = classEmitter.method(methodFlags, methodName, getStaticSignature());
 141         method.begin();
 142 
 143         // Load correct scope by calling getProto() on the scope argument as often as specified
 144         // by the second argument.
 145         final Label parentLoopStart = new Label("parent_loop_start");
 146         final Label parentLoopDone  = new Label("parent_loop_done");
 147         method.load(Type.OBJECT, 0);
 148         method.label(parentLoopStart);
 149         method.load(Type.INT, 1);
 150         method.iinc(1, -1);
 151         method.ifle(parentLoopDone);
 152         method.invoke(ScriptObject.GET_PROTO);
 153         method._goto(parentLoopStart);
 154         method.label(parentLoopDone);
 155 
 156         assert !isCall || valueType.isObject(); // Callables are always objects
 157         // If flags are optimistic, but we're doing a call, remove optimistic flags from the getter, as they obviously
 158         // only apply to the call.
 159         method.dynamicGet(valueType, symbol.getName(), isCall ? CodeGenerator.nonOptimisticFlags(flags) : flags, isCall, false);
 160 
 161         // If this is a get we're done, otherwise call the value as function.
 162         if (isCall) {
 163             method.convert(Type.OBJECT);
 164             // ScriptFunction will see CALLSITE_SCOPE and will bind scope accordingly.
 165             method.loadUndefined(Type.OBJECT);
 166             int slot = 2;
 167             for (final Type type : paramTypes) {
 168                 method.load(type, slot);
 169                 slot += type.getSlots();
 170             }
 171             // Shared scope calls disabled in optimistic world. TODO is this right?
 172             method.dynamicCall(returnType, 2 + paramTypes.length, flags);
 173         }
 174 
 175         method._return(returnType);
 176         method.end();
 177     }
 178 
 179     private String getStaticSignature() {