changeset 825:21fe19543736

Merge
author attila
date Fri, 21 Mar 2014 17:52:03 +0100
parents d7807721d24a 62ee612afc3e
children a6b199203eb8
files make/build.xml make/project.properties src/jdk/nashorn/api/scripting/NashornScriptEngine.java src/jdk/nashorn/api/scripting/ScriptObjectMirror.java src/jdk/nashorn/internal/codegen/Attr.java src/jdk/nashorn/internal/codegen/CodeGenerator.java src/jdk/nashorn/internal/codegen/ConstantData.java src/jdk/nashorn/internal/codegen/FindScopeDepths.java src/jdk/nashorn/internal/codegen/SharedScopeCall.java src/jdk/nashorn/internal/ir/FunctionNode.java src/jdk/nashorn/internal/objects/AccessorPropertyDescriptor.java src/jdk/nashorn/internal/objects/ArrayBufferView.java src/jdk/nashorn/internal/objects/DataPropertyDescriptor.java src/jdk/nashorn/internal/objects/GenericPropertyDescriptor.java src/jdk/nashorn/internal/objects/Global.java src/jdk/nashorn/internal/objects/NativeArray.java src/jdk/nashorn/internal/objects/NativeArrayBuffer.java src/jdk/nashorn/internal/objects/NativeDataView.java src/jdk/nashorn/internal/objects/NativeDebug.java src/jdk/nashorn/internal/objects/NativeError.java src/jdk/nashorn/internal/objects/NativeJSAdapter.java src/jdk/nashorn/internal/objects/NativeJavaImporter.java src/jdk/nashorn/internal/objects/NativeNumber.java src/jdk/nashorn/internal/objects/NativeRegExp.java src/jdk/nashorn/internal/objects/NativeStrictArguments.java src/jdk/nashorn/internal/objects/NativeString.java src/jdk/nashorn/internal/objects/ScriptFunctionImpl.java src/jdk/nashorn/internal/parser/Parser.java src/jdk/nashorn/internal/runtime/AccessorProperty.java src/jdk/nashorn/internal/runtime/Context.java src/jdk/nashorn/internal/runtime/DebuggerSupport.java src/jdk/nashorn/internal/runtime/ECMAErrors.java src/jdk/nashorn/internal/runtime/FinalScriptFunctionData.java src/jdk/nashorn/internal/runtime/GlobalObject.java src/jdk/nashorn/internal/runtime/JSONFunctions.java src/jdk/nashorn/internal/runtime/JSType.java src/jdk/nashorn/internal/runtime/NativeJavaPackage.java src/jdk/nashorn/internal/runtime/Property.java src/jdk/nashorn/internal/runtime/PropertyListener.java src/jdk/nashorn/internal/runtime/PropertyListenerManager.java src/jdk/nashorn/internal/runtime/PropertyMap.java src/jdk/nashorn/internal/runtime/RecompilableScriptFunctionData.java src/jdk/nashorn/internal/runtime/ScriptFunction.java src/jdk/nashorn/internal/runtime/ScriptFunctionData.java src/jdk/nashorn/internal/runtime/ScriptObject.java src/jdk/nashorn/internal/runtime/ScriptRuntime.java src/jdk/nashorn/internal/runtime/SetMethodCreator.java src/jdk/nashorn/internal/runtime/UserAccessorProperty.java src/jdk/nashorn/internal/runtime/WithObject.java src/jdk/nashorn/internal/runtime/arrays/ArrayData.java src/jdk/nashorn/internal/runtime/arrays/ByteBufferArrayData.java src/jdk/nashorn/internal/runtime/linker/JavaAdapterFactory.java src/jdk/nashorn/internal/runtime/linker/NashornGuards.java src/jdk/nashorn/internal/runtime/linker/NashornPrimitiveLinker.java src/jdk/nashorn/internal/runtime/resources/Messages.properties src/jdk/nashorn/internal/scripts/JO.java src/jdk/nashorn/tools/Shell.java test/script/basic/dataview_new.js test/script/currently-failing/OptimisticRecompilationTest.java test/src/jdk/nashorn/internal/codegen/CompilerTest.java test/src/jdk/nashorn/internal/runtime/OptimisticRecompilationTest.java
diffstat 97 files changed, 3504 insertions(+), 1922 deletions(-) [+]
line wrap: on
line diff
--- a/.hgtags	Thu Mar 20 16:26:54 2014 +0100
+++ b/.hgtags	Fri Mar 21 17:52:03 2014 +0100
@@ -236,3 +236,4 @@
 32631eed0fad2b31346eb41b29a50227bd29e2ec jdk9-b00
 65347535840f045f2cd4341d7466c51009b1b06f jdk9-b01
 b3517e51f40477f10db8bc30a557aa0ea712c274 jdk9-b02
+832f89ff25d903c45cfc994553f1ade8821a4398 jdk9-b03
--- a/buildtools/nasgen/src/jdk/nashorn/internal/tools/nasgen/ClassGenerator.java	Thu Mar 20 16:26:54 2014 +0100
+++ b/buildtools/nasgen/src/jdk/nashorn/internal/tools/nasgen/ClassGenerator.java	Fri Mar 21 17:52:03 2014 +0100
@@ -50,8 +50,6 @@
 import static jdk.nashorn.internal.tools.nasgen.StringConstants.COLLECTIONS_EMPTY_LIST;
 import static jdk.nashorn.internal.tools.nasgen.StringConstants.PROPERTYMAP_DESC;
 import static jdk.nashorn.internal.tools.nasgen.StringConstants.PROPERTYMAP_FIELD_NAME;
-import static jdk.nashorn.internal.tools.nasgen.StringConstants.PROPERTYMAP_SETISSHARED;
-import static jdk.nashorn.internal.tools.nasgen.StringConstants.PROPERTYMAP_SETISSHARED_DESC;
 import static jdk.nashorn.internal.tools.nasgen.StringConstants.PROPERTYMAP_NEWMAP;
 import static jdk.nashorn.internal.tools.nasgen.StringConstants.PROPERTYMAP_NEWMAP_DESC;
 import static jdk.nashorn.internal.tools.nasgen.StringConstants.PROPERTYMAP_TYPE;
@@ -191,8 +189,6 @@
         // stack: Collection
         // pmap = PropertyMap.newMap(Collection<Property>);
         mi.invokeStatic(PROPERTYMAP_TYPE, PROPERTYMAP_NEWMAP, PROPERTYMAP_NEWMAP_DESC);
-        // pmap.setIsShared();
-        mi.invokeVirtual(PROPERTYMAP_TYPE, PROPERTYMAP_SETISSHARED, PROPERTYMAP_SETISSHARED_DESC);
         // $nasgenmap$ = pmap;
         mi.putStatic(className, PROPERTYMAP_FIELD_NAME, PROPERTYMAP_DESC);
         mi.returnVoid();
--- a/buildtools/nasgen/src/jdk/nashorn/internal/tools/nasgen/ConstructorGenerator.java	Thu Mar 20 16:26:54 2014 +0100
+++ b/buildtools/nasgen/src/jdk/nashorn/internal/tools/nasgen/ConstructorGenerator.java	Fri Mar 21 17:52:03 2014 +0100
@@ -33,10 +33,7 @@
 import static jdk.nashorn.internal.tools.nasgen.StringConstants.DEFAULT_INIT_DESC;
 import static jdk.nashorn.internal.tools.nasgen.StringConstants.INIT;
 import static jdk.nashorn.internal.tools.nasgen.StringConstants.PROPERTYMAP_DESC;
-import static jdk.nashorn.internal.tools.nasgen.StringConstants.PROPERTYMAP_DUPLICATE;
-import static jdk.nashorn.internal.tools.nasgen.StringConstants.PROPERTYMAP_DUPLICATE_DESC;
 import static jdk.nashorn.internal.tools.nasgen.StringConstants.PROPERTYMAP_FIELD_NAME;
-import static jdk.nashorn.internal.tools.nasgen.StringConstants.PROPERTYMAP_TYPE;
 import static jdk.nashorn.internal.tools.nasgen.StringConstants.OBJECT_DESC;
 import static jdk.nashorn.internal.tools.nasgen.StringConstants.PROTOTYPEOBJECT_SETCONSTRUCTOR;
 import static jdk.nashorn.internal.tools.nasgen.StringConstants.PROTOTYPEOBJECT_SETCONSTRUCTOR_DESC;
@@ -171,9 +168,6 @@
     private void loadMap(final MethodGenerator mi) {
         if (memberCount > 0) {
             mi.getStatic(className, PROPERTYMAP_FIELD_NAME, PROPERTYMAP_DESC);
-            // make sure we use duplicated PropertyMap so that original map
-            // stays intact and so can be used for many globals.
-            mi.invokeVirtual(PROPERTYMAP_TYPE, PROPERTYMAP_DUPLICATE, PROPERTYMAP_DUPLICATE_DESC);
         }
     }
 
--- a/buildtools/nasgen/src/jdk/nashorn/internal/tools/nasgen/PrototypeGenerator.java	Thu Mar 20 16:26:54 2014 +0100
+++ b/buildtools/nasgen/src/jdk/nashorn/internal/tools/nasgen/PrototypeGenerator.java	Fri Mar 21 17:52:03 2014 +0100
@@ -32,10 +32,7 @@
 import static jdk.nashorn.internal.tools.nasgen.StringConstants.DEFAULT_INIT_DESC;
 import static jdk.nashorn.internal.tools.nasgen.StringConstants.INIT;
 import static jdk.nashorn.internal.tools.nasgen.StringConstants.PROPERTYMAP_DESC;
-import static jdk.nashorn.internal.tools.nasgen.StringConstants.PROPERTYMAP_DUPLICATE;
-import static jdk.nashorn.internal.tools.nasgen.StringConstants.PROPERTYMAP_DUPLICATE_DESC;
 import static jdk.nashorn.internal.tools.nasgen.StringConstants.PROPERTYMAP_FIELD_NAME;
-import static jdk.nashorn.internal.tools.nasgen.StringConstants.PROPERTYMAP_TYPE;
 import static jdk.nashorn.internal.tools.nasgen.StringConstants.OBJECT_DESC;
 import static jdk.nashorn.internal.tools.nasgen.StringConstants.PROTOTYPEOBJECT_TYPE;
 import static jdk.nashorn.internal.tools.nasgen.StringConstants.PROTOTYPE_SUFFIX;
@@ -129,7 +126,6 @@
             mi.getStatic(className, PROPERTYMAP_FIELD_NAME, PROPERTYMAP_DESC);
             // make sure we use duplicated PropertyMap so that original map
             // stays intact and so can be used for many global.
-            mi.invokeVirtual(PROPERTYMAP_TYPE, PROPERTYMAP_DUPLICATE, PROPERTYMAP_DUPLICATE_DESC);
             mi.invokeSpecial(PROTOTYPEOBJECT_TYPE, INIT, SCRIPTOBJECT_INIT_DESC);
             // initialize Function type fields
             initFunctionFields(mi);
--- a/buildtools/nasgen/src/jdk/nashorn/internal/tools/nasgen/StringConstants.java	Thu Mar 20 16:26:54 2014 +0100
+++ b/buildtools/nasgen/src/jdk/nashorn/internal/tools/nasgen/StringConstants.java	Fri Mar 21 17:52:03 2014 +0100
@@ -45,11 +45,9 @@
 @SuppressWarnings("javadoc")
 public interface StringConstants {
     // standard jdk types, methods
-    static final Type TYPE_METHOD             = Type.getType(Method.class);
     static final Type TYPE_METHODHANDLE       = Type.getType(MethodHandle.class);
     static final Type TYPE_METHODHANDLE_ARRAY = Type.getType(MethodHandle[].class);
     static final Type TYPE_OBJECT             = Type.getType(Object.class);
-    static final Type TYPE_CLASS              = Type.getType(Class.class);
     static final Type TYPE_STRING             = Type.getType(String.class);
     static final Type TYPE_COLLECTION         = Type.getType(Collection.class);
     static final Type TYPE_COLLECTIONS        = Type.getType(Collections.class);
@@ -104,10 +102,6 @@
     static final String PROPERTYMAP_DESC = TYPE_PROPERTYMAP.getDescriptor();
     static final String PROPERTYMAP_NEWMAP = "newMap";
     static final String PROPERTYMAP_NEWMAP_DESC = Type.getMethodDescriptor(TYPE_PROPERTYMAP, TYPE_COLLECTION);
-    static final String PROPERTYMAP_DUPLICATE = "duplicate";
-    static final String PROPERTYMAP_DUPLICATE_DESC = Type.getMethodDescriptor(TYPE_PROPERTYMAP);
-    static final String PROPERTYMAP_SETISSHARED = "setIsShared";
-    static final String PROPERTYMAP_SETISSHARED_DESC = Type.getMethodDescriptor(TYPE_PROPERTYMAP);
 
     // PrototypeObject
     static final String PROTOTYPEOBJECT_TYPE = TYPE_PROTOTYPEOBJECT.getInternalName();
--- a/make/BuildNashorn.gmk	Thu Mar 20 16:26:54 2014 +0100
+++ b/make/BuildNashorn.gmk	Fri Mar 21 17:52:03 2014 +0100
@@ -77,7 +77,7 @@
 	$(RM) -rf $(@D)/jdk $(@D)/netscape
 	$(CP) -R -p $(NASHORN_OUTPUTDIR)/nashorn_classes/* $(@D)/
 	$(FIXPATH) $(JAVA) \
-	    -cp "$(NASHORN_OUTPUTDIR)/nasgen_classes$(PATH_SEP)$(NASHORN_OUTPUTDIR)/nashorn_classes" \
+	    -Xbootclasspath/p:"$(NASHORN_OUTPUTDIR)/nasgen_classes$(PATH_SEP)$(NASHORN_OUTPUTDIR)/nashorn_classes" \
 	    jdk.nashorn.internal.tools.nasgen.Main $(@D) jdk.nashorn.internal.objects $(@D)
 	$(TOUCH) $@
 
--- a/make/build.xml	Thu Mar 20 16:26:54 2014 +0100
+++ b/make/build.xml	Fri Mar 21 17:52:03 2014 +0100
@@ -125,6 +125,7 @@
       <compilerarg value="-Xlint:unchecked"/>
       <compilerarg value="-Xlint:deprecation"/>
       <compilerarg value="-XDignore.symbol.file"/>
+      <compilerarg value="-Xdiags:verbose"/>
     </javac>
     <copy todir="${build.classes.dir}/META-INF/services">
        <fileset dir="${meta.inf.dir}/services/"/>
@@ -243,6 +244,7 @@
         <compilerarg value="-J-Djava.ext.dirs="/>
         <compilerarg value="-Xlint:unchecked"/>
         <compilerarg value="-Xlint:deprecation"/>
+        <compilerarg value="-Xdiags:verbose"/>
     </javac>
 
     <copy todir="${build.test.classes.dir}/META-INF/services">
@@ -253,6 +255,10 @@
        <fileset dir="${test.src.dir}/jdk/nashorn/internal/runtime/resources"/>
     </copy>
 
+    <copy todir="${build.test.classes.dir}/jdk/nashorn/api/scripting/resources">
+       <fileset dir="${test.src.dir}/jdk/nashorn/api/scripting/resources"/>
+    </copy>
+
     <!-- tests that check nashorn internals and internal API -->
     <jar jarfile="${nashorn.internal.tests.jar}">
       <fileset dir="${build.test.classes.dir}" excludes="**/api/**"/>
--- a/make/project.properties	Thu Mar 20 16:26:54 2014 +0100
+++ b/make/project.properties	Fri Mar 21 17:52:03 2014 +0100
@@ -206,7 +206,7 @@
 
 # test262 test frameworks
 test262-test-sys-prop.test.js.framework=\
-    --class-cache-size=0 \
+    --class-cache-size=10 \
     --no-java \
     --no-typed-arrays \
     -timezone=PST \
--- a/src/jdk/nashorn/api/scripting/NashornScriptEngine.java	Thu Mar 20 16:26:54 2014 +0100
+++ b/src/jdk/nashorn/api/scripting/NashornScriptEngine.java	Fri Mar 21 17:52:03 2014 +0100
@@ -57,9 +57,9 @@
 import javax.script.ScriptEngineFactory;
 import javax.script.ScriptException;
 import javax.script.SimpleBindings;
+import jdk.nashorn.internal.objects.Global;
 import jdk.nashorn.internal.runtime.Context;
 import jdk.nashorn.internal.runtime.ErrorManager;
-import jdk.nashorn.internal.runtime.GlobalObject;
 import jdk.nashorn.internal.runtime.Property;
 import jdk.nashorn.internal.runtime.ScriptEnvironment;
 import jdk.nashorn.internal.runtime.ScriptFunction;
@@ -100,7 +100,7 @@
     private final boolean             _global_per_engine;
     // This is the initial default Nashorn global object.
     // This is used as "shared" global if above option is true.
-    private final ScriptObject        global;
+    private final Global              global;
     // initialized bit late to be made 'final'.
     // Property object for "context" property of global object.
     private volatile Property         contextProperty;
@@ -265,7 +265,7 @@
     public Object __noSuchProperty__(final Object self, final ScriptContext ctxt, final String name) {
         if (ctxt != null) {
             final int scope = ctxt.getAttributesScope(name);
-            final ScriptObject ctxtGlobal = getNashornGlobalFrom(ctxt);
+            final Global ctxtGlobal = getNashornGlobalFrom(ctxt);
             if (scope != -1) {
                 return ScriptObjectMirror.unwrap(ctxt.getAttribute(name, scope), ctxtGlobal);
             }
@@ -318,7 +318,7 @@
         }
 
         ScriptObject realSelf = null;
-        ScriptObject realGlobal = null;
+        Global realGlobal = null;
         if(thiz == null) {
             // making interface out of global functions
             realSelf = realGlobal = getNashornGlobalFrom(context);
@@ -347,7 +347,7 @@
         }
 
         try {
-            final ScriptObject oldGlobal = Context.getGlobal();
+            final Global oldGlobal = Context.getGlobal();
             final boolean globalChanged = (oldGlobal != realGlobal);
             try {
                 if (globalChanged) {
@@ -372,7 +372,7 @@
     }
 
     // Retrieve nashorn Global object for a given ScriptContext object
-    private ScriptObject getNashornGlobalFrom(final ScriptContext ctxt) {
+    private Global getNashornGlobalFrom(final ScriptContext ctxt) {
         if (_global_per_engine) {
             // shared single global object for all ENGINE_SCOPE Bindings
             return global;
@@ -381,18 +381,18 @@
         final Bindings bindings = ctxt.getBindings(ScriptContext.ENGINE_SCOPE);
         // is this Nashorn's own Bindings implementation?
         if (bindings instanceof ScriptObjectMirror) {
-            final ScriptObject sobj = globalFromMirror((ScriptObjectMirror)bindings);
-            if (sobj != null) {
-                return sobj;
+            final Global glob = globalFromMirror((ScriptObjectMirror)bindings);
+            if (glob != null) {
+                return glob;
             }
         }
 
         // Arbitrary user Bindings implementation. Look for NASHORN_GLOBAL in it!
         Object scope = bindings.get(NASHORN_GLOBAL);
         if (scope instanceof ScriptObjectMirror) {
-            final ScriptObject sobj = globalFromMirror((ScriptObjectMirror)scope);
-            if (sobj != null) {
-                return sobj;
+            final Global glob = globalFromMirror((ScriptObjectMirror)scope);
+            if (glob != null) {
+                return glob;
             }
         }
 
@@ -400,14 +400,14 @@
         // Create new global instance mirror and associate with the Bindings.
         final ScriptObjectMirror mirror = createGlobalMirror(ctxt);
         bindings.put(NASHORN_GLOBAL, mirror);
-        return mirror.getScriptObject();
+        return mirror.getHomeGlobal();
     }
 
     // Retrieve nashorn Global object from a given ScriptObjectMirror
-    private ScriptObject globalFromMirror(final ScriptObjectMirror mirror) {
+    private Global globalFromMirror(final ScriptObjectMirror mirror) {
         ScriptObject sobj = mirror.getScriptObject();
-        if (sobj instanceof GlobalObject && isOfContext(sobj, nashornContext)) {
-            return sobj;
+        if (sobj instanceof Global && isOfContext((Global)sobj, nashornContext)) {
+            return (Global)sobj;
         }
 
         return null;
@@ -415,15 +415,15 @@
 
     // Create a new ScriptObjectMirror wrapping a newly created Nashorn Global object
     private ScriptObjectMirror createGlobalMirror(final ScriptContext ctxt) {
-        final ScriptObject newGlobal = createNashornGlobal(ctxt);
+        final Global newGlobal = createNashornGlobal(ctxt);
         return new ScriptObjectMirror(newGlobal, newGlobal);
     }
 
     // Create a new Nashorn Global object
-    private ScriptObject createNashornGlobal(final ScriptContext ctxt) {
-        final ScriptObject newGlobal = AccessController.doPrivileged(new PrivilegedAction<ScriptObject>() {
+    private Global createNashornGlobal(final ScriptContext ctxt) {
+        final Global newGlobal = AccessController.doPrivileged(new PrivilegedAction<Global>() {
             @Override
-            public ScriptObject run() {
+            public Global run() {
                 try {
                     return nashornContext.newGlobal();
                 } catch (final RuntimeException e) {
@@ -461,7 +461,7 @@
     }
 
     // scripts should see "context" and "engine" as variables in the given global object
-    private void setContextVariables(final ScriptObject ctxtGlobal, final ScriptContext ctxt) {
+    private void setContextVariables(final Global ctxtGlobal, final ScriptContext ctxt) {
         // set "context" global variable via contextProperty - because this
         // property is non-writable
         contextProperty.setValue(ctxtGlobal, ctxtGlobal, ctxt, false);
@@ -471,7 +471,7 @@
         }
         // if no arguments passed, expose it
         if (! (args instanceof ScriptObject)) {
-            args = ((GlobalObject)ctxtGlobal).wrapAsObject(args);
+            args = ctxtGlobal.wrapAsObject(args);
             ctxtGlobal.set("arguments", args, false);
         }
     }
@@ -479,7 +479,7 @@
     private Object invokeImpl(final Object selfObject, final String name, final Object... args) throws ScriptException, NoSuchMethodException {
         name.getClass(); // null check
 
-        ScriptObject invokeGlobal = null;
+        Global invokeGlobal = null;
         ScriptObjectMirror selfMirror = null;
         if (selfObject instanceof ScriptObjectMirror) {
             selfMirror = (ScriptObjectMirror)selfObject;
@@ -490,7 +490,7 @@
         } else if (selfObject instanceof ScriptObject) {
             // invokeMethod called from script code - in which case we may get 'naked' ScriptObject
             // Wrap it with oldGlobal to make a ScriptObjectMirror for the same.
-            final ScriptObject oldGlobal = Context.getGlobal();
+            final Global oldGlobal = Context.getGlobal();
             invokeGlobal = oldGlobal;
             if (oldGlobal == null) {
                 throw new IllegalArgumentException(getMessage("no.current.nashorn.global"));
@@ -503,7 +503,7 @@
             selfMirror = (ScriptObjectMirror)ScriptObjectMirror.wrap(selfObject, oldGlobal);
         } else if (selfObject == null) {
             // selfObject is null => global function call
-            final ScriptObject ctxtGlobal = getNashornGlobalFrom(context);
+            final Global ctxtGlobal = getNashornGlobalFrom(context);
             invokeGlobal = ctxtGlobal;
             selfMirror = (ScriptObjectMirror)ScriptObjectMirror.wrap(ctxtGlobal, ctxtGlobal);
         }
@@ -533,11 +533,11 @@
         return evalImpl(script, ctxt, getNashornGlobalFrom(ctxt));
     }
 
-    private Object evalImpl(final ScriptFunction script, final ScriptContext ctxt, final ScriptObject ctxtGlobal) throws ScriptException {
+    private Object evalImpl(final ScriptFunction script, final ScriptContext ctxt, final Global ctxtGlobal) throws ScriptException {
         if (script == null) {
             return null;
         }
-        final ScriptObject oldGlobal = Context.getGlobal();
+        final Global oldGlobal = Context.getGlobal();
         final boolean globalChanged = (oldGlobal != ctxtGlobal);
         try {
             if (globalChanged) {
@@ -559,7 +559,7 @@
         }
     }
 
-    private static void throwAsScriptException(final Exception e, final ScriptObject global) throws ScriptException {
+    private static void throwAsScriptException(final Exception e, final Global global) throws ScriptException {
         if (e instanceof ScriptException) {
             throw (ScriptException)e;
         } else if (e instanceof NashornException) {
@@ -583,7 +583,7 @@
         return new CompiledScript() {
             @Override
             public Object eval(final ScriptContext ctxt) throws ScriptException {
-                final ScriptObject globalObject = getNashornGlobalFrom(ctxt);
+                final Global globalObject = getNashornGlobalFrom(ctxt);
                 // Are we running the script in the correct global?
                 if (func.getScope() == globalObject) {
                     return evalImpl(func, ctxt, globalObject);
@@ -612,8 +612,8 @@
         return compileImpl(source, getNashornGlobalFrom(ctxt));
     }
 
-    private ScriptFunction compileImpl(final Source source, final ScriptObject newGlobal) throws ScriptException {
-        final ScriptObject oldGlobal = Context.getGlobal();
+    private ScriptFunction compileImpl(final Source source, final Global newGlobal) throws ScriptException {
+        final Global oldGlobal = Context.getGlobal();
         final boolean globalChanged = (oldGlobal != newGlobal);
         try {
             if (globalChanged) {
@@ -651,8 +651,7 @@
         return true;
     }
 
-    private static boolean isOfContext(final ScriptObject global, final Context context) {
-        assert global instanceof GlobalObject: "Not a Global object";
-        return ((GlobalObject)global).isOfContext(context);
+    private static boolean isOfContext(final Global global, final Context context) {
+        return global.isOfContext(context);
     }
 }
--- a/src/jdk/nashorn/api/scripting/ScriptObjectMirror.java	Thu Mar 20 16:26:54 2014 +0100
+++ b/src/jdk/nashorn/api/scripting/ScriptObjectMirror.java	Fri Mar 21 17:52:03 2014 +0100
@@ -42,10 +42,10 @@
 import java.util.Set;
 import java.util.concurrent.Callable;
 import javax.script.Bindings;
+import jdk.nashorn.internal.objects.Global;
 import jdk.nashorn.internal.runtime.arrays.ArrayData;
 import jdk.nashorn.internal.runtime.ConsString;
 import jdk.nashorn.internal.runtime.Context;
-import jdk.nashorn.internal.runtime.GlobalObject;
 import jdk.nashorn.internal.runtime.JSType;
 import jdk.nashorn.internal.runtime.ScriptFunction;
 import jdk.nashorn.internal.runtime.ScriptObject;
@@ -64,7 +64,7 @@
     private static final AccessControlContext GET_CONTEXT_ACC_CTXT = getContextAccCtxt();
 
     private final ScriptObject sobj;
-    private final ScriptObject global;
+    private final Global  global;
     private final boolean strict;
 
     @Override
@@ -95,7 +95,7 @@
 
     @Override
     public Object call(final Object thiz, final Object... args) {
-        final ScriptObject oldGlobal = Context.getGlobal();
+        final Global oldGlobal = Context.getGlobal();
         final boolean globalChanged = (oldGlobal != global);
 
         try {
@@ -125,7 +125,7 @@
 
     @Override
     public Object newObject(final Object... args) {
-        final ScriptObject oldGlobal = Context.getGlobal();
+        final Global oldGlobal = Context.getGlobal();
         final boolean globalChanged = (oldGlobal != global);
 
         try {
@@ -177,7 +177,7 @@
      */
     public Object callMember(final String functionName, final Object... args) {
         functionName.getClass(); // null check
-        final ScriptObject oldGlobal = Context.getGlobal();
+        final Global oldGlobal = Context.getGlobal();
         final boolean globalChanged = (oldGlobal != global);
 
         try {
@@ -648,7 +648,7 @@
      */
     public static Object wrap(final Object obj, final Object homeGlobal) {
         if(obj instanceof ScriptObject) {
-            return homeGlobal instanceof ScriptObject ? new ScriptObjectMirror((ScriptObject)obj, (ScriptObject)homeGlobal) : obj;
+            return homeGlobal instanceof Global ? new ScriptObjectMirror((ScriptObject)obj, (Global)homeGlobal) : obj;
         }
         if(obj instanceof ConsString) {
             return obj.toString();
@@ -716,13 +716,13 @@
 
     // package-privates below this.
 
-    ScriptObjectMirror(final ScriptObject sobj, final ScriptObject global) {
+    ScriptObjectMirror(final ScriptObject sobj, final Global global) {
         assert sobj != null : "ScriptObjectMirror on null!";
-        assert global instanceof GlobalObject : "global is not a GlobalObject";
+        assert global != null : "home Global is null";
 
         this.sobj = sobj;
         this.global = global;
-        this.strict = ((GlobalObject)global).isStrictContext();
+        this.strict = global.isStrictContext();
     }
 
     // accessors for script engine
@@ -730,7 +730,7 @@
         return sobj;
     }
 
-    ScriptObject getHomeGlobal() {
+    Global getHomeGlobal() {
         return global;
     }
 
@@ -740,7 +740,7 @@
 
     // internals only below this.
     private <V> V inGlobal(final Callable<V> callable) {
-        final ScriptObject oldGlobal = Context.getGlobal();
+        final Global oldGlobal = Context.getGlobal();
         final boolean globalChanged = (oldGlobal != global);
         if (globalChanged) {
             Context.setGlobal(global);
--- a/src/jdk/nashorn/internal/codegen/Attr.java	Thu Mar 20 16:26:54 2014 +0100
+++ b/src/jdk/nashorn/internal/codegen/Attr.java	Fri Mar 21 17:52:03 2014 +0100
@@ -410,10 +410,11 @@
      * @return Symbol for given name or null for redefinition.
      */
     private Symbol defineSymbol(final Block block, final String name, final int symbolFlags) {
-        int    flags  = symbolFlags;
-        Symbol symbol = findSymbol(block, name); // Locate symbol.
+        int     flags    = symbolFlags;
+        Symbol  symbol   = findSymbol(block, name); // Locate symbol.
+        boolean isGlobal = (flags & KINDMASK) == IS_GLOBAL;
 
-        if ((flags & KINDMASK) == IS_GLOBAL) {
+        if (isGlobal) {
             flags |= IS_SCOPE;
         }
 
@@ -453,6 +454,8 @@
             // Determine where to create it.
             if ((flags & Symbol.KINDMASK) == IS_VAR && ((flags & IS_INTERNAL) == IS_INTERNAL || (flags & IS_LET) == IS_LET)) {
                 symbolBlock = block; //internal vars are always defined in the block closest to them
+            } else if (isGlobal) {
+                symbolBlock = lc.getOutermostFunction().getBody();
             } else {
                 symbolBlock = lc.getFunctionBody(function);
             }
--- a/src/jdk/nashorn/internal/codegen/CodeGenerator.java	Thu Mar 20 16:26:54 2014 +0100
+++ b/src/jdk/nashorn/internal/codegen/CodeGenerator.java	Fri Mar 21 17:52:03 2014 +0100
@@ -74,7 +74,6 @@
 import java.util.RandomAccess;
 import java.util.Set;
 import java.util.TreeMap;
-
 import jdk.nashorn.internal.codegen.ClassEmitter.Flag;
 import jdk.nashorn.internal.codegen.CompilerConstants.Call;
 import jdk.nashorn.internal.codegen.RuntimeCallSite.SpecializedRuntimeNode;
@@ -891,7 +890,7 @@
                     void loadStack() {
                         load(node, Type.OBJECT); // foo() makes no sense if foo == 3
                         // ScriptFunction will see CALLSITE_SCOPE and will bind scope accordingly.
-                        method.loadNull(); //the 'this'
+                        method.loadUndefined(Type.OBJECT); //the 'this'
                         argsCount = loadArgs(args);
                     }
                     @Override
@@ -1079,7 +1078,7 @@
                     void loadStack() {
                         // Load up function.
                         load(function, Type.OBJECT); //TODO, e.g. booleans can be used as functions
-                        method.loadNull(); // ScriptFunction will figure out the correct this when it sees CALLSITE_SCOPE
+                        method.loadUndefined(Type.OBJECT); // ScriptFunction will figure out the correct this when it sees CALLSITE_SCOPE
                         argsCount = loadArgs(args);
                         }
                         @Override
@@ -1088,7 +1087,6 @@
                             dynamicCall(method, callNode, callNodeType, 2 + argsCount, flags);
                         }
                 }.emit(callNode);
-
                 return false;
             }
         });
--- a/src/jdk/nashorn/internal/codegen/ConstantData.java	Thu Mar 20 16:26:54 2014 +0100
+++ b/src/jdk/nashorn/internal/codegen/ConstantData.java	Fri Mar 21 17:52:03 2014 +0100
@@ -30,6 +30,8 @@
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
+import jdk.nashorn.internal.runtime.Property;
+import jdk.nashorn.internal.runtime.PropertyMap;
 
 /**
  * Manages constants needed by code generation.  Objects are maintained in an
@@ -110,6 +112,43 @@
     }
 
     /**
+     * {@link PropertyMap} wrapper class that provides implementations for the {@code hashCode} and {@code equals}
+     * methods that are based on the map layout. {@code PropertyMap} itself inherits the identity based implementations
+     * from {@code java.lang.Object}.
+     */
+    private static class PropertyMapWrapper {
+        private final PropertyMap propertyMap;
+        private final int hashCode;
+
+        public PropertyMapWrapper(final PropertyMap map) {
+            int hash = 0;
+            for (final Property property : map.getProperties()) {
+                hash = hash << 7 ^ hash >> 7;
+                hash ^= property.hashCode();
+            }
+            this.hashCode = hash;
+            this.propertyMap = map;
+        }
+
+        @Override
+        public int hashCode() {
+            return hashCode;
+        }
+
+        @Override
+        public boolean equals(final Object other) {
+            if (!(other instanceof PropertyMapWrapper)) {
+                return false;
+            }
+
+            final Property[] ownProperties = propertyMap.getProperties();
+            final Property[] otherProperties = ((PropertyMapWrapper) other).propertyMap.getProperties();
+
+            return Arrays.equals(ownProperties, otherProperties);
+        }
+    }
+
+    /**
      * Constructor
      */
     ConstantData() {
@@ -146,7 +185,14 @@
      */
     public int add(final Object object) {
         assert object != null;
-        final Object  entry = object.getClass().isArray() ? new ArrayWrapper(object) : object;
+        final Object  entry;
+        if (object.getClass().isArray()) {
+            entry = new ArrayWrapper(object);
+        } else if (object instanceof PropertyMap) {
+            entry = new PropertyMapWrapper((PropertyMap) object);
+        } else {
+            entry = object;
+        }
         final Integer value = objectMap.get(entry);
 
         if (value != null) {
--- a/src/jdk/nashorn/internal/codegen/FindScopeDepths.java	Thu Mar 20 16:26:54 2014 +0100
+++ b/src/jdk/nashorn/internal/codegen/FindScopeDepths.java	Fri Mar 21 17:52:03 2014 +0100
@@ -33,7 +33,6 @@
 import java.util.Iterator;
 import java.util.Map;
 import java.util.Set;
-
 import jdk.nashorn.internal.ir.Block;
 import jdk.nashorn.internal.ir.Expression;
 import jdk.nashorn.internal.ir.FunctionNode;
--- a/src/jdk/nashorn/internal/codegen/SharedScopeCall.java	Thu Mar 20 16:26:54 2014 +0100
+++ b/src/jdk/nashorn/internal/codegen/SharedScopeCall.java	Fri Mar 21 17:52:03 2014 +0100
@@ -162,7 +162,7 @@
         if (isCall) {
             method.convert(Type.OBJECT);
             // ScriptFunction will see CALLSITE_SCOPE and will bind scope accordingly.
-            method.loadNull();
+            method.loadUndefined(Type.OBJECT);
             int slot = 2;
             for (final Type type : paramTypes) {
                 method.load(type, slot);
--- a/src/jdk/nashorn/internal/ir/FunctionNode.java	Thu Mar 20 16:26:54 2014 +0100
+++ b/src/jdk/nashorn/internal/ir/FunctionNode.java	Fri Mar 21 17:52:03 2014 +0100
@@ -205,6 +205,9 @@
      */
     public static final int IS_PROGRAM = 1 << 14;
 
+    /** Does this function use the "this" keyword? */
+    public static final int USES_THIS                   = 1 << 15;
+
     /** Does this function or any nested functions contain an eval? */
     private static final int HAS_DEEP_EVAL = HAS_EVAL | HAS_NESTED_EVAL;
 
@@ -558,6 +561,15 @@
     }
 
     /**
+     * Return {@code true} if this function makes use of the {@code this} object.
+     *
+     * @return true if function uses {@code this} object
+     */
+    public boolean usesThis() {
+        return getFlag(USES_THIS);
+    }
+
+    /**
      * Get the identifier for this function, this is its symbol.
      * @return the identifier as an IdentityNode
      */
--- a/src/jdk/nashorn/internal/objects/AccessorPropertyDescriptor.java	Thu Mar 20 16:26:54 2014 +0100
+++ b/src/jdk/nashorn/internal/objects/AccessorPropertyDescriptor.java	Fri Mar 21 17:52:03 2014 +0100
@@ -68,12 +68,8 @@
     // initialized by nasgen
     private static PropertyMap $nasgenmap$;
 
-    static PropertyMap getInitialMap() {
-        return $nasgenmap$;
-    }
-
     AccessorPropertyDescriptor(final boolean configurable, final boolean enumerable, final Object get, final Object set, final Global global) {
-        super(global.getObjectPrototype(), global.getAccessorPropertyDescriptorMap());
+        super(global.getObjectPrototype(), $nasgenmap$);
         this.configurable = configurable;
         this.enumerable   = enumerable;
         this.get          = get;
--- a/src/jdk/nashorn/internal/objects/ArrayBufferView.java	Thu Mar 20 16:26:54 2014 +0100
+++ b/src/jdk/nashorn/internal/objects/ArrayBufferView.java	Fri Mar 21 17:52:03 2014 +0100
@@ -31,7 +31,6 @@
 
 import java.nio.ByteBuffer;
 import java.nio.ByteOrder;
-
 import jdk.internal.dynalink.CallSiteDescriptor;
 import jdk.internal.dynalink.linker.GuardedInvocation;
 import jdk.internal.dynalink.linker.LinkRequest;
@@ -53,12 +52,8 @@
     // initialized by nasgen
     private static PropertyMap $nasgenmap$;
 
-    static PropertyMap getInitialMap() {
-        return $nasgenmap$;
-    }
-
     private ArrayBufferView(final NativeArrayBuffer buffer, final int byteOffset, final int elementLength, final Global global) {
-        super(global.getArrayBufferViewMap());
+        super($nasgenmap$);
 
         final int bytesPerElement = bytesPerElement();
 
--- a/src/jdk/nashorn/internal/objects/DataPropertyDescriptor.java	Thu Mar 20 16:26:54 2014 +0100
+++ b/src/jdk/nashorn/internal/objects/DataPropertyDescriptor.java	Fri Mar 21 17:52:03 2014 +0100
@@ -65,12 +65,8 @@
     // initialized by nasgen
     private static PropertyMap $nasgenmap$;
 
-    static PropertyMap getInitialMap() {
-        return $nasgenmap$;
-    }
-
     DataPropertyDescriptor(final boolean configurable, final boolean enumerable, final boolean writable, final Object value, final Global global) {
-        super(global.getObjectPrototype(), global.getDataPropertyDescriptorMap());
+        super(global.getObjectPrototype(), $nasgenmap$);
         this.configurable = configurable;
         this.enumerable   = enumerable;
         this.writable     = writable;
--- a/src/jdk/nashorn/internal/objects/GenericPropertyDescriptor.java	Thu Mar 20 16:26:54 2014 +0100
+++ b/src/jdk/nashorn/internal/objects/GenericPropertyDescriptor.java	Fri Mar 21 17:52:03 2014 +0100
@@ -56,12 +56,8 @@
     // initialized by nasgen
     private static PropertyMap $nasgenmap$;
 
-    static PropertyMap getInitialMap() {
-        return $nasgenmap$;
-    }
-
     GenericPropertyDescriptor(final boolean configurable, final boolean enumerable, final Global global) {
-        super(global.getObjectPrototype(), global.getGenericPropertyDescriptorMap());
+        super(global.getObjectPrototype(), $nasgenmap$);
         this.configurable = configurable;
         this.enumerable   = enumerable;
     }
--- a/src/jdk/nashorn/internal/objects/Global.java	Thu Mar 20 16:26:54 2014 +0100
+++ b/src/jdk/nashorn/internal/objects/Global.java	Fri Mar 21 17:52:03 2014 +0100
@@ -33,11 +33,8 @@
 import java.io.PrintWriter;
 import java.lang.invoke.MethodHandle;
 import java.lang.invoke.MethodHandles;
-import java.lang.ref.ReferenceQueue;
-import java.lang.ref.SoftReference;
 import java.lang.reflect.Field;
 import java.util.Arrays;
-import java.util.LinkedHashMap;
 import java.util.Map;
 import java.util.concurrent.Callable;
 import java.util.concurrent.ConcurrentHashMap;
@@ -50,7 +47,6 @@
 import jdk.nashorn.internal.runtime.ConsString;
 import jdk.nashorn.internal.runtime.Context;
 import jdk.nashorn.internal.runtime.GlobalFunctions;
-import jdk.nashorn.internal.runtime.GlobalObject;
 import jdk.nashorn.internal.runtime.JSType;
 import jdk.nashorn.internal.runtime.NativeJavaPackage;
 import jdk.nashorn.internal.runtime.PropertyDescriptor;
@@ -58,10 +54,10 @@
 import jdk.nashorn.internal.runtime.Scope;
 import jdk.nashorn.internal.runtime.ScriptEnvironment;
 import jdk.nashorn.internal.runtime.ScriptFunction;
+import jdk.nashorn.internal.runtime.ScriptFunctionData;
 import jdk.nashorn.internal.runtime.ScriptObject;
 import jdk.nashorn.internal.runtime.ScriptRuntime;
 import jdk.nashorn.internal.runtime.ScriptingFunctions;
-import jdk.nashorn.internal.runtime.Source;
 import jdk.nashorn.internal.runtime.arrays.ArrayData;
 import jdk.nashorn.internal.runtime.linker.Bootstrap;
 import jdk.nashorn.internal.runtime.linker.InvokeByName;
@@ -72,10 +68,9 @@
  * Representation of global scope.
  */
 @ScriptClass("Global")
-public final class Global extends ScriptObject implements GlobalObject, Scope {
+public final class Global extends ScriptObject implements Scope {
     // Placeholder value used in place of a location property (__FILE__, __DIR__, __LINE__)
     private static final Object LOCATION_PROPERTY_PLACEHOLDER = new Object();
-
     private final InvokeByName TO_STRING = new InvokeByName("toString", ScriptObject.class);
     private final InvokeByName VALUE_OF  = new InvokeByName("valueOf",  ScriptObject.class);
 
@@ -231,6 +226,10 @@
     @Property(name = "ArrayBuffer", attributes = Attribute.NOT_ENUMERABLE)
     public volatile Object arrayBuffer;
 
+    /** DataView object */
+    @Property(name = "DataView", attributes = Attribute.NOT_ENUMERABLE)
+    public volatile Object dataView;
+
     /** TypedArray (int8) */
     @Property(name = "Int8Array", attributes = Attribute.NOT_ENUMERABLE)
     public volatile Object int8Array;
@@ -357,6 +356,7 @@
     private ScriptObject   builtinJavaImporter;
     private ScriptObject   builtinJavaApi;
     private ScriptObject   builtinArrayBuffer;
+    private ScriptObject   builtinDataView;
     private ScriptObject   builtinInt8Array;
     private ScriptObject   builtinUint8Array;
     private ScriptObject   builtinUint8ClampedArray;
@@ -372,42 +372,9 @@
      */
     private ScriptFunction typeErrorThrower;
 
-    private PropertyMap    accessorPropertyDescriptorMap;
-    private PropertyMap    arrayBufferViewMap;
-    private PropertyMap    dataPropertyDescriptorMap;
-    private PropertyMap    genericPropertyDescriptorMap;
-    private PropertyMap    nativeArgumentsMap;
-    private PropertyMap    nativeArrayMap;
-    private PropertyMap    nativeArrayBufferMap;
-    private PropertyMap    nativeBooleanMap;
-    private PropertyMap    nativeDateMap;
-    private PropertyMap    nativeErrorMap;
-    private PropertyMap    nativeEvalErrorMap;
-    private PropertyMap    nativeJSAdapterMap;
-    private PropertyMap    nativeJavaImporterMap;
-    private PropertyMap    nativeNumberMap;
-    private PropertyMap    nativeRangeErrorMap;
-    private PropertyMap    nativeReferenceErrorMap;
-    private PropertyMap    nativeRegExpMap;
-    private PropertyMap    nativeRegExpExecResultMap;
-    private PropertyMap    nativeStrictArgumentsMap;
-    private PropertyMap    nativeStringMap;
-    private PropertyMap    nativeSyntaxErrorMap;
-    private PropertyMap    nativeTypeErrorMap;
-    private PropertyMap    nativeURIErrorMap;
-    private PropertyMap    prototypeObjectMap;
-    private PropertyMap    objectMap;
-    private PropertyMap    functionMap;
-    private PropertyMap    anonymousFunctionMap;
-    private PropertyMap    strictFunctionMap;
-    private PropertyMap    boundFunctionMap;
-
     // Flag to indicate that a split method issued a return statement
     private int splitState = -1;
 
-    // class cache
-    private ClassCache classCache;
-
     // Used to store the last RegExp result to support deprecated RegExp constructor properties
     private RegExpResult lastRegExpResult;
 
@@ -458,11 +425,6 @@
         super(checkAndGetMap(context));
         this.context = context;
         this.setIsScope();
-
-        final int cacheSize = context.getEnv()._class_cache_size;
-        if (cacheSize > 0) {
-            classCache = new ClassCache(cacheSize);
-        }
     }
 
     /**
@@ -471,11 +433,9 @@
      * @return the global singleton
      */
     public static Global instance() {
-        final ScriptObject global = Context.getGlobal();
-        if (! (global instanceof Global)) {
-            throw new IllegalStateException("no current global instance");
-        }
-        return (Global)global;
+        final Global global = Context.getGlobal();
+        global.getClass(); // null check
+        return global;
     }
 
     /**
@@ -496,19 +456,30 @@
         return instance().getContext();
     }
 
-    // GlobalObject interface implementation
+    // Runtime interface to Global
 
-    @Override
+    /**
+     * Is this global of the given Context?
+     * @param ctxt the context
+     * @return true if this global belongs to the given Context
+     */
     public boolean isOfContext(final Context ctxt) {
         return this.context == ctxt;
     }
 
-    @Override
+    /**
+     * Does this global belong to a strict Context?
+     * @return true if this global belongs to a strict Context
+     */
     public boolean isStrictContext() {
         return context.getEnv()._strict;
     }
 
-    @Override
+    /**
+     * Initialize standard builtin objects like "Object", "Array", "Function" etc.
+     * as well as our extension builtin objects like "Java", "JSAdapter" as properties
+     * of the global scope object.
+     */
     public void initBuiltinObjects() {
         if (this.builtinObject != null) {
             // already initialized, just return
@@ -518,12 +489,26 @@
         init();
     }
 
-    @Override
+    /**
+     * Create a new ScriptFunction object
+     *
+     * @param name   function name
+     * @param handle invocation handle for function
+     * @param scope  the scope
+     * @param strict are we in strict mode
+     *
+     * @return new script function
+     */
     public ScriptFunction newScriptFunction(final String name, final MethodHandle handle, final ScriptObject scope, final boolean strict) {
-        return new ScriptFunctionImpl(name, handle, scope, null, strict, false, true);
+        return new ScriptFunctionImpl(name, handle, scope, null, strict ? ScriptFunctionData.IS_STRICT_CONSTRUCTOR : ScriptFunctionData.IS_CONSTRUCTOR);
     }
 
-    @Override
+    /**
+     * Wrap a Java object as corresponding script object
+     *
+     * @param obj object to wrap
+     * @return    wrapped object
+     */
     public Object wrapAsObject(final Object obj) {
         if (obj instanceof Boolean) {
             return new NativeBoolean((Boolean)obj, this);
@@ -545,7 +530,14 @@
         }
     }
 
-    @Override
+    /**
+     * Lookup helper for JS primitive types
+     *
+     * @param request the link request for the dynamic call site.
+     * @param self     self reference
+     *
+     * @return guarded invocation
+     */
     public GuardedInvocation primitiveLookup(final LinkRequest request, final Object self) {
         if (self instanceof String || self instanceof ConsString) {
             return NativeString.lookupPrimitive(request, self);
@@ -557,12 +549,23 @@
         throw new IllegalArgumentException("Unsupported primitive: " + self);
     }
 
-    @Override
+    /**
+     * Create a new empty script object
+     *
+     * @return the new ScriptObject
+     */
     public ScriptObject newObject() {
-        return new JO(getObjectPrototype(), getObjectMap());
+        return new JO(getObjectPrototype(), JO.getInitialMap());
     }
 
-    @Override
+    /**
+     * Default value of given type
+     *
+     * @param sobj     script object
+     * @param typeHint type hint
+     *
+     * @return default value
+     */
     public Object getDefaultValue(final ScriptObject sobj, final Class<?> typeHint) {
         // When the [[DefaultValue]] internal method of O is called with no hint,
         // then it behaves as if the hint were Number, unless O is a Date object
@@ -622,7 +625,12 @@
         return UNDEFINED;
     }
 
-    @Override
+    /**
+     * Is the given ScriptObject an ECMAScript Error object?
+     *
+     * @param sobj the object being checked
+     * @return true if sobj is an Error object
+     */
     public boolean isError(final ScriptObject sobj) {
         final ScriptObject errorProto = getErrorPrototype();
         ScriptObject proto = sobj.getProto();
@@ -635,52 +643,108 @@
         return false;
     }
 
-    @Override
+    /**
+     * Create a new ECMAScript Error object.
+     *
+     * @param msg error message
+     * @return newly created Error object
+     */
     public ScriptObject newError(final String msg) {
         return new NativeError(msg, this);
     }
 
-    @Override
+    /**
+     * Create a new ECMAScript EvalError object.
+     *
+     * @param msg error message
+     * @return newly created EvalError object
+     */
     public ScriptObject newEvalError(final String msg) {
         return new NativeEvalError(msg, this);
     }
 
-    @Override
+    /**
+     * Create a new ECMAScript RangeError object.
+     *
+     * @param msg error message
+     * @return newly created RangeError object
+     */
     public ScriptObject newRangeError(final String msg) {
         return new NativeRangeError(msg, this);
     }
 
-    @Override
+    /**
+     * Create a new ECMAScript ReferenceError object.
+     *
+     * @param msg error message
+     * @return newly created ReferenceError object
+     */
     public ScriptObject newReferenceError(final String msg) {
         return new NativeReferenceError(msg, this);
     }
 
-    @Override
+    /**
+     * Create a new ECMAScript SyntaxError object.
+     *
+     * @param msg error message
+     * @return newly created SyntaxError object
+     */
     public ScriptObject newSyntaxError(final String msg) {
         return new NativeSyntaxError(msg, this);
     }
 
-    @Override
+    /**
+     * Create a new ECMAScript TypeError object.
+     *
+     * @param msg error message
+     * @return newly created TypeError object
+     */
     public ScriptObject newTypeError(final String msg) {
         return new NativeTypeError(msg, this);
     }
 
-    @Override
+    /**
+     * Create a new ECMAScript URIError object.
+     *
+     * @param msg error message
+     * @return newly created URIError object
+     */
     public ScriptObject newURIError(final String msg) {
         return new NativeURIError(msg, this);
     }
 
-    @Override
+    /**
+     * Create a new ECMAScript GenericDescriptor object.
+     *
+     * @param configurable is the property configurable?
+     * @param enumerable is the property enumerable?
+     * @return newly created GenericDescriptor object
+     */
     public PropertyDescriptor newGenericDescriptor(final boolean configurable, final boolean enumerable) {
         return new GenericPropertyDescriptor(configurable, enumerable, this);
     }
 
-    @Override
+    /**
+     * Create a new ECMAScript DatePropertyDescriptor object.
+     *
+     * @param value of the data property
+     * @param configurable is the property configurable?
+     * @param enumerable is the property enumerable?
+     * @return newly created DataPropertyDescriptor object
+     */
     public PropertyDescriptor newDataDescriptor(final Object value, final boolean configurable, final boolean enumerable, final boolean writable) {
         return new DataPropertyDescriptor(configurable, enumerable, writable, value, this);
     }
 
-    @Override
+    /**
+     * Create a new ECMAScript AccessorPropertyDescriptor object.
+     *
+     * @param get getter function of the user accessor property
+     * @param set setter function of the user accessor property
+     * @param configurable is the property configurable?
+     * @param enumerable is the property enumerable?
+     * @return newly created AccessorPropertyDescriptor object
+     */
     public PropertyDescriptor newAccessorDescriptor(final Object get, final Object set, final boolean configurable, final boolean enumerable) {
         final AccessorPropertyDescriptor desc = new AccessorPropertyDescriptor(configurable, enumerable, get == null ? UNDEFINED : get, set == null ? UNDEFINED : set, this);
 
@@ -695,63 +759,6 @@
         return desc;
     }
 
-
-    /**
-     * Cache for compiled script classes.
-     */
-    @SuppressWarnings("serial")
-    private static class ClassCache extends LinkedHashMap<Source, ClassReference> {
-        private final int size;
-        private final ReferenceQueue<Class<?>> queue;
-
-        ClassCache(final int size) {
-            super(size, 0.75f, true);
-            this.size = size;
-            this.queue = new ReferenceQueue<>();
-        }
-
-        void cache(final Source source, final Class<?> clazz) {
-            put(source, new ClassReference(clazz, queue, source));
-        }
-
-        @Override
-        protected boolean removeEldestEntry(final Map.Entry<Source, ClassReference> eldest) {
-            return size() > size;
-        }
-
-        @Override
-        public ClassReference get(final Object key) {
-            for (ClassReference ref; (ref = (ClassReference)queue.poll()) != null; ) {
-                remove(ref.source);
-            }
-            return super.get(key);
-        }
-
-    }
-
-    private static class ClassReference extends SoftReference<Class<?>> {
-        private final Source source;
-
-        ClassReference(final Class<?> clazz, final ReferenceQueue<Class<?>> queue, final Source source) {
-            super(clazz, queue);
-            this.source = source;
-        }
-    }
-
-    // Class cache management
-    @Override
-    public Class<?> findCachedClass(final Source source) {
-        assert classCache != null : "Class cache used without being initialized";
-        final ClassReference ref = classCache.get(source);
-        return ref != null ? ref.get() : null;
-    }
-
-    @Override
-    public void cacheClass(final Source source, final Class<?> clazz) {
-        assert classCache != null : "Class cache used without being initialized";
-        classCache.cache(source, clazz);
-    }
-
     private static <T> T getLazilyCreatedValue(final Object key, final Callable<T> creator, final Map<Object, T> map) {
         final T obj = map.get(key);
         if (obj != null) {
@@ -769,14 +776,25 @@
 
     private final Map<Object, InvokeByName> namedInvokers = new ConcurrentHashMap<>();
 
-    @Override
+
+    /**
+     * Get cached InvokeByName object for the given key
+     * @param key key to be associated with InvokeByName object
+     * @param creator if InvokeByName is absent 'creator' is called to make one (lazy init)
+     * @return InvokeByName object associated with the key.
+     */
     public InvokeByName getInvokeByName(final Object key, final Callable<InvokeByName> creator) {
         return getLazilyCreatedValue(key, creator, namedInvokers);
     }
 
     private final Map<Object, MethodHandle> dynamicInvokers = new ConcurrentHashMap<>();
 
-    @Override
+    /**
+     * Get cached dynamic method handle for the given key
+     * @param key key to be associated with dynamic method handle
+     * @param creator if method handle is absent 'creator' is called to make one (lazy init)
+     * @return dynamic method handle associated with the key.
+     */
     public MethodHandle getDynamicInvoker(final Object key, final Callable<MethodHandle> creator) {
         return getLazilyCreatedValue(key, creator, dynamicInvokers);
     }
@@ -965,6 +983,10 @@
         return ScriptFunction.getPrototype(builtinArrayBuffer);
     }
 
+    ScriptObject getDataViewPrototype() {
+        return ScriptFunction.getPrototype(builtinDataView);
+    }
+
     ScriptObject getInt8ArrayPrototype() {
         return ScriptFunction.getPrototype(builtinInt8Array);
     }
@@ -1001,123 +1023,6 @@
         return ScriptFunction.getPrototype(builtinFloat64Array);
     }
 
-    // Builtin PropertyMap accessors
-    PropertyMap getAccessorPropertyDescriptorMap() {
-        return accessorPropertyDescriptorMap;
-    }
-
-    PropertyMap getArrayBufferViewMap() {
-        return arrayBufferViewMap;
-    }
-
-    PropertyMap getDataPropertyDescriptorMap() {
-        return dataPropertyDescriptorMap;
-    }
-
-    PropertyMap getGenericPropertyDescriptorMap() {
-        return genericPropertyDescriptorMap;
-    }
-
-    PropertyMap getArgumentsMap() {
-        return nativeArgumentsMap;
-    }
-
-    PropertyMap getArrayMap() {
-        return nativeArrayMap;
-    }
-
-    PropertyMap getArrayBufferMap() {
-        return nativeArrayBufferMap;
-    }
-
-    PropertyMap getBooleanMap() {
-        return nativeBooleanMap;
-    }
-
-    PropertyMap getDateMap() {
-        return nativeDateMap;
-    }
-
-    PropertyMap getErrorMap() {
-        return nativeErrorMap;
-    }
-
-    PropertyMap getEvalErrorMap() {
-        return nativeEvalErrorMap;
-    }
-
-    PropertyMap getJSAdapterMap() {
-        return nativeJSAdapterMap;
-    }
-
-    PropertyMap getJavaImporterMap() {
-        return nativeJavaImporterMap;
-    }
-
-    PropertyMap getNumberMap() {
-        return nativeNumberMap;
-    }
-
-    PropertyMap getRangeErrorMap() {
-        return nativeRangeErrorMap;
-    }
-
-    PropertyMap getReferenceErrorMap() {
-        return nativeReferenceErrorMap;
-    }
-
-    PropertyMap getRegExpMap() {
-        return nativeRegExpMap;
-    }
-
-    PropertyMap getRegExpExecResultMap() {
-        return nativeRegExpExecResultMap;
-    }
-
-    PropertyMap getStrictArgumentsMap() {
-        return nativeStrictArgumentsMap;
-    }
-
-    PropertyMap getStringMap() {
-        return nativeStringMap;
-    }
-
-    PropertyMap getSyntaxErrorMap() {
-        return nativeSyntaxErrorMap;
-    }
-
-    PropertyMap getTypeErrorMap() {
-        return nativeTypeErrorMap;
-    }
-
-    PropertyMap getURIErrorMap() {
-        return nativeURIErrorMap;
-    }
-
-    PropertyMap getPrototypeObjectMap() {
-        return prototypeObjectMap;
-    }
-
-    PropertyMap getObjectMap() {
-        return objectMap;
-    }
-
-    PropertyMap getFunctionMap() {
-        return functionMap;
-    }
-
-    PropertyMap getAnonymousFunctionMap() {
-        return anonymousFunctionMap;
-    }
-
-    PropertyMap getStrictFunctionMap() {
-        return strictFunctionMap;
-    }
-
-    PropertyMap getBoundFunctionMap() {
-        return boundFunctionMap;
-    }
-
     private ScriptFunction getBuiltinArray() {
         return builtinArray;
     }
@@ -1655,13 +1560,11 @@
 
         final ScriptEnvironment env = getContext().getEnv();
 
-        // duplicate PropertyMaps of Native* classes
-        copyInitialMaps(env);
         // initialize Function and Object constructor
         initFunctionAndObject();
 
         // Now fix Global's own proto.
-        this.setProto(getObjectPrototype());
+        this.setInitialProto(getObjectPrototype());
 
         // initialize global function properties
         this.eval = this.builtinEval = ScriptFunctionImpl.makeFunction("eval", EVAL);
@@ -1801,7 +1704,7 @@
         final ScriptObject prototype = ScriptFunction.getPrototype(cons);
         prototype.set(NativeError.NAME, name, false);
         prototype.set(NativeError.MESSAGE, "", false);
-        prototype.setProto(errorProto);
+        prototype.setInitialProto(errorProto);
         return (ScriptFunction)cons;
     }
 
@@ -1869,6 +1772,7 @@
 
     private void initTypedArray() {
         this.builtinArrayBuffer       = initConstructor("ArrayBuffer");
+        this.builtinDataView          = initConstructor("DataView");
         this.builtinInt8Array         = initConstructor("Int8Array");
         this.builtinUint8Array        = initConstructor("Uint8Array");
         this.builtinUint8ClampedArray = initConstructor("Uint8ClampedArray");
@@ -1909,6 +1813,7 @@
         this.typeError         = this.builtinTypeError;
         this.uriError          = this.builtinURIError;
         this.arrayBuffer       = this.builtinArrayBuffer;
+        this.dataView          = this.builtinDataView;
         this.int8Array         = this.builtinInt8Array;
         this.uint8Array        = this.builtinUint8Array;
         this.uint8ClampedArray = this.builtinUint8ClampedArray;
@@ -1973,7 +1878,7 @@
             }
 
             if (res.getProto() == null) {
-                res.setProto(getObjectPrototype());
+                res.setInitialProto(getObjectPrototype());
             }
 
             return res;
@@ -1983,47 +1888,6 @@
         }
     }
 
-    private void copyInitialMaps(final ScriptEnvironment env) {
-        this.accessorPropertyDescriptorMap = AccessorPropertyDescriptor.getInitialMap().duplicate();
-        this.dataPropertyDescriptorMap = DataPropertyDescriptor.getInitialMap().duplicate();
-        this.genericPropertyDescriptorMap = GenericPropertyDescriptor.getInitialMap().duplicate();
-        this.nativeArgumentsMap = NativeArguments.getInitialMap().duplicate();
-        this.nativeArrayMap = NativeArray.getInitialMap().duplicate();
-        this.nativeBooleanMap = NativeBoolean.getInitialMap().duplicate();
-        this.nativeDateMap = NativeDate.getInitialMap().duplicate();
-        this.nativeErrorMap = NativeError.getInitialMap().duplicate();
-        this.nativeEvalErrorMap = NativeEvalError.getInitialMap().duplicate();
-        this.nativeJSAdapterMap = NativeJSAdapter.getInitialMap().duplicate();
-        this.nativeNumberMap = NativeNumber.getInitialMap().duplicate();
-        this.nativeRangeErrorMap = NativeRangeError.getInitialMap().duplicate();
-        this.nativeReferenceErrorMap = NativeReferenceError.getInitialMap().duplicate();
-        this.nativeRegExpMap = NativeRegExp.getInitialMap().duplicate();
-        this.nativeRegExpExecResultMap = NativeRegExpExecResult.getInitialMap().duplicate();
-        this.nativeStrictArgumentsMap = NativeStrictArguments.getInitialMap().duplicate();
-        this.nativeStringMap = NativeString.getInitialMap().duplicate();
-        this.nativeSyntaxErrorMap = NativeSyntaxError.getInitialMap().duplicate();
-        this.nativeTypeErrorMap = NativeTypeError.getInitialMap().duplicate();
-        this.nativeURIErrorMap = NativeURIError.getInitialMap().duplicate();
-        this.prototypeObjectMap = PrototypeObject.getInitialMap().duplicate();
-        this.objectMap = JO.getInitialMap().duplicate();
-        this.functionMap = ScriptFunctionImpl.getInitialMap().duplicate();
-        this.anonymousFunctionMap = ScriptFunctionImpl.getInitialAnonymousMap().duplicate();
-        this.strictFunctionMap = ScriptFunctionImpl.getInitialStrictMap().duplicate();
-        assert strictFunctionMap != null;
-        this.boundFunctionMap = ScriptFunctionImpl.getInitialBoundMap().duplicate();
-
-        // java
-        if (! env._no_java) {
-            this.nativeJavaImporterMap = NativeJavaImporter.getInitialMap().duplicate();
-        }
-
-        // typed arrays
-        if (! env._no_typed_arrays) {
-            this.arrayBufferViewMap = ArrayBufferView.getInitialMap().duplicate();
-            this.nativeArrayBufferMap = NativeArrayBuffer.getInitialMap().duplicate();
-        }
-    }
-
     // Function and Object constructors are inter-dependent. Also,
     // Function.prototype
     // functions are not properly initialized. We fix the references here.
@@ -2041,13 +1905,13 @@
 
         // Function.prototype === Object.getPrototypeOf(Function) ===
         // <anon-function>
-        builtinFunction.setProto(anon);
+        builtinFunction.setInitialProto(anon);
         builtinFunction.setPrototype(anon);
         anon.set("constructor", builtinFunction, false);
         anon.deleteOwnProperty(anon.getMap().findProperty("prototype"));
 
         // use "getter" so that [[ThrowTypeError]] function's arity is 0 - as specified in step 10 of section 13.2.3
-        this.typeErrorThrower = new ScriptFunctionImpl("TypeErrorThrower", Lookup.TYPE_ERROR_THROWER_GETTER, null, null, false, false, false);
+        this.typeErrorThrower = new ScriptFunctionImpl("TypeErrorThrower", Lookup.TYPE_ERROR_THROWER_GETTER, null, null, 0);
         typeErrorThrower.setPrototype(UNDEFINED);
         // Non-constructor built-in functions do not have "prototype" property
         typeErrorThrower.deleteOwnProperty(typeErrorThrower.getMap().findProperty("prototype"));
@@ -2057,7 +1921,7 @@
         this.builtinObject = (ScriptFunction)initConstructor("Object");
         final ScriptObject ObjectPrototype = getObjectPrototype();
         // Object.getPrototypeOf(Function.prototype) === Object.prototype
-        anon.setProto(ObjectPrototype);
+        anon.setInitialProto(ObjectPrototype);
 
         // Function valued properties of Function.prototype were not properly
         // initialized. Because, these were created before global.function and
@@ -2069,10 +1933,10 @@
 
             if (value instanceof ScriptFunction && value != anon) {
                 final ScriptFunction func = (ScriptFunction)value;
-                func.setProto(getFunctionPrototype());
+                func.setInitialProto(getFunctionPrototype());
                 final ScriptObject prototype = ScriptFunction.getPrototype(func);
                 if (prototype != null) {
-                    prototype.setProto(ObjectPrototype);
+                    prototype.setInitialProto(ObjectPrototype);
                 }
             }
         }
@@ -2087,7 +1951,7 @@
                 final ScriptFunction func = (ScriptFunction)value;
                 final ScriptObject prototype = ScriptFunction.getPrototype(func);
                 if (prototype != null) {
-                    prototype.setProto(ObjectPrototype);
+                    prototype.setInitialProto(ObjectPrototype);
                 }
             }
         }
@@ -2105,7 +1969,7 @@
                 final ScriptFunction func = (ScriptFunction)value;
                 final ScriptObject prototype = ScriptFunction.getPrototype(func);
                 if (prototype != null) {
-                    prototype.setProto(ObjectPrototype);
+                    prototype.setInitialProto(ObjectPrototype);
                 }
             }
         }
--- a/src/jdk/nashorn/internal/objects/NativeArguments.java	Thu Mar 20 16:26:54 2014 +0100
+++ b/src/jdk/nashorn/internal/objects/NativeArguments.java	Fri Mar 21 17:52:03 2014 +0100
@@ -68,7 +68,7 @@
         final ArrayList<Property> properties = new ArrayList<>(2);
         properties.add(AccessorProperty.create("length", Property.NOT_ENUMERABLE, G$LENGTH, S$LENGTH));
         properties.add(AccessorProperty.create("callee", Property.NOT_ENUMERABLE, G$CALLEE, S$CALLEE));
-        map$ = PropertyMap.newMap(properties).setIsShared();
+        map$ = PropertyMap.newMap(properties);
     }
 
     static PropertyMap getInitialMap() {
@@ -267,9 +267,9 @@
         final Global global = Global.instance();
         final ScriptObject proto = global.getObjectPrototype();
         if (isStrict) {
-            return new NativeStrictArguments(arguments, numParams, proto, global.getStrictArgumentsMap());
+            return new NativeStrictArguments(arguments, numParams, proto, NativeStrictArguments.getInitialMap());
         }
-        return new NativeArguments(arguments, callee, numParams, proto, global.getArgumentsMap());
+        return new NativeArguments(arguments, callee, numParams, proto, NativeArguments.getInitialMap());
     }
 
     /**
--- a/src/jdk/nashorn/internal/objects/NativeArray.java	Thu Mar 20 16:26:54 2014 +0100
+++ b/src/jdk/nashorn/internal/objects/NativeArray.java	Fri Mar 21 17:52:03 2014 +0100
@@ -40,7 +40,6 @@
 import java.util.Iterator;
 import java.util.List;
 import java.util.concurrent.Callable;
-
 import jdk.internal.dynalink.CallSiteDescriptor;
 import jdk.internal.dynalink.linker.GuardedInvocation;
 import jdk.internal.dynalink.linker.LinkRequest;
@@ -134,7 +133,7 @@
     }
 
     NativeArray(final ArrayData arrayData, final Global global) {
-        super(global.getArrayPrototype(), global.getArrayMap());
+        super(global.getArrayPrototype(), $nasgenmap$);
         this.setArray(arrayData);
         this.setIsArray();
     }
@@ -243,10 +242,6 @@
     // initialized by nasgen
     private static PropertyMap $nasgenmap$;
 
-    static PropertyMap getInitialMap() {
-        return $nasgenmap$;
-    }
-
     @Override
     public String getClassName() {
         return "Array";
--- a/src/jdk/nashorn/internal/objects/NativeArrayBuffer.java	Thu Mar 20 16:26:54 2014 +0100
+++ b/src/jdk/nashorn/internal/objects/NativeArrayBuffer.java	Fri Mar 21 17:52:03 2014 +0100
@@ -28,7 +28,6 @@
 import static jdk.nashorn.internal.runtime.ECMAErrors.typeError;
 
 import java.nio.ByteBuffer;
-
 import jdk.nashorn.internal.objects.annotations.Attribute;
 import jdk.nashorn.internal.objects.annotations.Constructor;
 import jdk.nashorn.internal.objects.annotations.Function;
@@ -51,17 +50,6 @@
     // initialized by nasgen
     private static PropertyMap $nasgenmap$;
 
-    static PropertyMap getInitialMap() {
-        return $nasgenmap$;
-    }
-
-    /**
-     * Constructor
-     * @param newObj is this a new call
-     * @param self   self
-     * @param args   arguments
-     * @return new native array buffer
-     */
     @Constructor(arity = 1)
     public static Object constructor(final boolean newObj, final Object self, final Object... args) {
         if (!newObj) {
@@ -81,7 +69,7 @@
      * @param global global instance
      */
     protected NativeArrayBuffer(final ByteBuffer nb, final Global global) {
-        super(global.getArrayBufferPrototype(), global.getArrayBufferMap());
+        super(global.getArrayBufferPrototype(), $nasgenmap$);
         this.nb = nb;
     }
 
@@ -211,4 +199,18 @@
     int getByteLength() {
         return nb.limit();
     }
+
+    ByteBuffer getBuffer() {
+       return nb;
+    }
+
+    ByteBuffer getBuffer(final int offset) {
+        return (ByteBuffer)nb.duplicate().position(offset);
+//        return ByteBuffer.wrap(buffer, offset, buffer.length - offset);
+    }
+
+    ByteBuffer getBuffer(final int offset, final int length) {
+        return (ByteBuffer)getBuffer(offset).limit(length);
+        //return ByteBuffer.wrap(buffer, offset, length);
+    }
 }
--- a/src/jdk/nashorn/internal/objects/NativeBoolean.java	Thu Mar 20 16:26:54 2014 +0100
+++ b/src/jdk/nashorn/internal/objects/NativeBoolean.java	Fri Mar 21 17:52:03 2014 +0100
@@ -30,6 +30,7 @@
 
 import java.lang.invoke.MethodHandle;
 import java.lang.invoke.MethodHandles;
+import java.lang.invoke.MethodType;
 import jdk.internal.dynalink.linker.GuardedInvocation;
 import jdk.internal.dynalink.linker.LinkRequest;
 import jdk.nashorn.internal.objects.annotations.Attribute;
@@ -50,22 +51,21 @@
 public final class NativeBoolean extends ScriptObject {
     private final boolean value;
 
-    final static MethodHandle WRAPFILTER = findWrapFilter();
+    // Method handle to create an object wrapper for a primitive boolean
+    private static final MethodHandle WRAPFILTER = findOwnMH("wrapFilter", MH.type(NativeBoolean.class, Object.class));
+    // Method handle to retrieve the Boolean prototype object
+    private static final MethodHandle PROTOFILTER = findOwnMH("protoFilter", MH.type(Object.class, Object.class));
 
     // initialized by nasgen
     private static PropertyMap $nasgenmap$;
 
-    static PropertyMap getInitialMap() {
-        return $nasgenmap$;
-    }
-
     private NativeBoolean(final boolean value, final ScriptObject proto, final PropertyMap map) {
         super(proto, map);
         this.value = value;
     }
 
     NativeBoolean(final boolean flag, final Global global) {
-        this(flag, global.getBooleanPrototype(), global.getBooleanMap());
+        this(flag, global.getBooleanPrototype(), $nasgenmap$);
     }
 
     NativeBoolean(final boolean flag) {
@@ -164,7 +164,7 @@
      * @return Link to be invoked at call site.
      */
     public static GuardedInvocation lookupPrimitive(final LinkRequest request, final Object receiver) {
-        return PrimitiveLookup.lookupPrimitive(request, Boolean.class, new NativeBoolean((Boolean)receiver), WRAPFILTER);
+        return PrimitiveLookup.lookupPrimitive(request, Boolean.class, new NativeBoolean((Boolean)receiver), WRAPFILTER, PROTOFILTER);
     }
 
     /**
@@ -178,7 +178,12 @@
         return new NativeBoolean((Boolean)receiver);
     }
 
-    private static MethodHandle findWrapFilter() {
-        return MH.findStatic(MethodHandles.lookup(), NativeBoolean.class, "wrapFilter", MH.type(NativeBoolean.class, Object.class));
+    @SuppressWarnings("unused")
+    private static Object protoFilter(final Object object) {
+        return Global.instance().getBooleanPrototype();
+    }
+
+    private static MethodHandle findOwnMH(final String name, final MethodType type) {
+        return MH.findStatic(MethodHandles.lookup(), NativeBoolean.class, name, type);
     }
 }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/jdk/nashorn/internal/objects/NativeDataView.java	Fri Mar 21 17:52:03 2014 +0100
@@ -0,0 +1,1015 @@
+/*
+ * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package jdk.nashorn.internal.objects;
+
+import static jdk.nashorn.internal.runtime.ECMAErrors.rangeError;
+import static jdk.nashorn.internal.runtime.ECMAErrors.typeError;
+import static jdk.nashorn.internal.runtime.ScriptRuntime.UNDEFINED;
+
+import java.nio.ByteBuffer;
+import java.nio.ByteOrder;
+import jdk.nashorn.internal.objects.annotations.Attribute;
+import jdk.nashorn.internal.objects.annotations.Constructor;
+import jdk.nashorn.internal.objects.annotations.Function;
+import jdk.nashorn.internal.objects.annotations.Property;
+import jdk.nashorn.internal.objects.annotations.ScriptClass;
+import jdk.nashorn.internal.objects.annotations.SpecializedConstructor;
+import jdk.nashorn.internal.objects.annotations.SpecializedFunction;
+import jdk.nashorn.internal.runtime.JSType;
+import jdk.nashorn.internal.runtime.PropertyMap;
+import jdk.nashorn.internal.runtime.ScriptObject;
+import jdk.nashorn.internal.runtime.ScriptRuntime;
+
+/**
+ * <p>
+ * DataView builtin constructor. Based on the specification here:
+ * http://www.khronos.org/registry/typedarray/specs/latest/#8
+ * </p>
+ * <p>
+ * An ArrayBuffer is a useful object for representing an arbitrary chunk of data.
+ * In many cases, such data will be read from disk or from the network, and will
+ * not follow the alignment restrictions that are imposed on the typed array views
+ * described earlier. In addition, the data will often be heterogeneous in nature
+ * and have a defined byte order. The DataView view provides a low-level interface
+ * for reading such data from and writing it to an ArrayBuffer.
+ * </p>
+ * <p>
+ * Regardless of the host computer's endianness, DataView reads or writes values
+ * to or from main memory with a specified endianness: big or little.
+ * </p>
+ */
+@ScriptClass("DataView")
+public class NativeDataView extends ScriptObject {
+    // initialized by nasgen
+    private static PropertyMap $nasgenmap$;
+
+    // inherited ArrayBufferView properties
+
+    /**
+     * Underlying ArrayBuffer storage object
+     */
+    @Property(attributes = Attribute.NON_ENUMERABLE_CONSTANT)
+    public final Object buffer;
+
+    /**
+     * The offset in bytes from the start of the ArrayBuffer
+     */
+    @Property(attributes = Attribute.NON_ENUMERABLE_CONSTANT)
+    public final int byteOffset;
+
+    /**
+     * The number of bytes from the offset that this DataView will reference
+     */
+    @Property(attributes = Attribute.NON_ENUMERABLE_CONSTANT)
+    public final int byteLength;
+
+    // underlying ByteBuffer
+    private final ByteBuffer buf;
+
+    private NativeDataView(NativeArrayBuffer arrBuf) {
+        this(arrBuf, arrBuf.getBuffer(), 0);
+    }
+
+    private NativeDataView(NativeArrayBuffer arrBuf, int offset) {
+        this(arrBuf, bufferFrom(arrBuf, offset), offset);
+    }
+
+    private NativeDataView(NativeArrayBuffer arrBuf, int offset, int length) {
+        this(arrBuf, bufferFrom(arrBuf, offset, length), offset, length);
+    }
+
+    private NativeDataView(final NativeArrayBuffer arrBuf, final ByteBuffer buf, final int offset) {
+       this(arrBuf, buf, offset, buf.capacity() - offset);
+    }
+
+    private NativeDataView(final NativeArrayBuffer arrBuf, final ByteBuffer buf, final int offset, final int length) {
+        super(Global.instance().getDataViewPrototype(), $nasgenmap$);
+        this.buffer = arrBuf;
+        this.byteOffset = offset;
+        this.byteLength = length;
+        this.buf = buf;
+    }
+
+    /**
+     * Create a new DataView object using the passed ArrayBuffer for its
+     * storage. Optional byteOffset and byteLength can be used to limit the
+     * section of the buffer referenced. The byteOffset indicates the offset in
+     * bytes from the start of the ArrayBuffer, and the byteLength is the number
+     * of bytes from the offset that this DataView will reference. If both
+     * byteOffset and byteLength are omitted, the DataView spans the entire
+     * ArrayBuffer range. If the byteLength is omitted, the DataView extends from
+     * the given byteOffset until the end of the ArrayBuffer.
+     *
+     * If the given byteOffset and byteLength references an area beyond the end
+     * of the ArrayBuffer an exception is raised.
+
+     * @param newObj if this constructor was invoked with 'new' or not
+     * @param self   constructor function object
+     * @param args   arguments to the constructor
+     * @return newly constructed DataView object
+     */
+    @Constructor(arity = 1)
+    public static Object constructor(final boolean newObj, final Object self, final Object... args) {
+        if (args.length == 0 || !(args[0] instanceof NativeArrayBuffer)) {
+            throw typeError("not.an.arraybuffer.in.dataview");
+        }
+
+        final NativeArrayBuffer arrBuf = (NativeArrayBuffer) args[0];
+        switch (args.length) {
+            case 1:
+                return new NativeDataView(arrBuf);
+            case 2:
+                return new NativeDataView(arrBuf, JSType.toInt32(args[1]));
+            default:
+                return new NativeDataView(arrBuf, JSType.toInt32(args[1]), JSType.toInt32(args[2]));
+        }
+    }
+
+    /**
+     * Specialized version of DataView constructor
+     *
+     * @param newObj if this constructor was invoked with 'new' or not
+     * @param self   constructor function object
+     * @param arrBuf underlying ArrayBuffer storage object
+     * @param offset offset in bytes from the start of the ArrayBuffer
+     * @return newly constructed DataView object
+     */
+    @SpecializedConstructor
+    public static Object constructor(final boolean newObj, final Object self, final Object arrBuf, final int offset) {
+        if (!(arrBuf instanceof NativeArrayBuffer)) {
+            throw typeError("not.an.arraybuffer.in.dataview");
+        }
+        return new NativeDataView((NativeArrayBuffer) arrBuf, offset);
+    }
+
+    /**
+     * Specialized version of DataView constructor
+     *
+     * @param newObj if this constructor was invoked with 'new' or not
+     * @param self   constructor function object
+     * @param arrBuf underlying ArrayBuffer storage object
+     * @param offset in bytes from the start of the ArrayBuffer
+     * @param length is the number of bytes from the offset that this DataView will reference
+     * @return newly constructed DataView object
+     */
+    @SpecializedConstructor
+    public static Object constructor(final boolean newObj, final Object self, final Object arrBuf, final int offset, final int length) {
+        if (!(arrBuf instanceof NativeArrayBuffer)) {
+            throw typeError("not.an.arraybuffer.in.dataview");
+        }
+        return new NativeDataView((NativeArrayBuffer) arrBuf, offset, length);
+    }
+
+    // Gets the value of the given type at the specified byte offset
+    // from the start of the view. There is no alignment constraint;
+    // multi-byte values may be fetched from any offset.
+    //
+    // For multi-byte values, the optional littleEndian argument
+    // indicates whether a big-endian or little-endian value should be
+    // read. If false or undefined, a big-endian value is read.
+    //
+    // These methods raise an exception if they would read
+    // beyond the end of the view.
+
+    /**
+     * Get 8-bit signed int from given byteOffset
+     *
+     * @param self DataView object
+     * @param byteOffset byte offset to read from
+     * @return 8-bit signed int value at the byteOffset
+     */
+    @Function(attributes = Attribute.NOT_ENUMERABLE)
+    public static int getInt8(final Object self, final Object byteOffset) {
+        try {
+            return getBuffer(self).get(JSType.toInt32(byteOffset));
+        } catch (final IllegalArgumentException iae) {
+            throw rangeError(iae, "dataview.offset");
+        }
+    }
+
+    /**
+     * Get 8-bit signed int from given byteOffset
+     *
+     * @param self DataView object
+     * @param byteOffset byte offset to read from
+     * @return 8-bit signed int value at the byteOffset
+     */
+    @SpecializedFunction
+    public static int getInt8(final Object self, final int byteOffset) {
+        try {
+            return getBuffer(self).get(byteOffset);
+        } catch (final IllegalArgumentException iae) {
+            throw rangeError(iae, "dataview.offset");
+        }
+    }
+
+    /**
+     * Get 8-bit unsigned int from given byteOffset
+     *
+     * @param self DataView object
+     * @param byteOffset byte offset to read from
+     * @return 8-bit unsigned int value at the byteOffset
+     */
+    @Function(attributes = Attribute.NOT_ENUMERABLE)
+    public static int getUint8(final Object self, final Object byteOffset) {
+        try {
+            return (0xFF & getBuffer(self).get(JSType.toInt32(byteOffset)));
+        } catch (final IllegalArgumentException iae) {
+            throw rangeError(iae, "dataview.offset");
+        }
+    }
+
+    /**
+     * Get 8-bit unsigned int from given byteOffset
+     *
+     * @param self DataView object
+     * @param byteOffset byte offset to read from
+     * @return 8-bit unsigned int value at the byteOffset
+     */
+    @SpecializedFunction
+    public static int getUint8(final Object self, final int byteOffset) {
+        try {
+            return (0xFF & getBuffer(self).get(byteOffset));
+        } catch (final IllegalArgumentException iae) {
+            throw rangeError(iae, "dataview.offset");
+        }
+    }
+
+    /**
+     * Get 16-bit signed int from given byteOffset
+     *
+     * @param self DataView object
+     * @param byteOffset byte offset to read from
+     * @param littleEndian (optional) flag indicating whether to read in little endian order
+     * @return 16-bit signed int value at the byteOffset
+     */
+    @Function(attributes = Attribute.NOT_ENUMERABLE, arity = 1)
+    public static int getInt16(final Object self, final Object byteOffset, final Object littleEndian) {
+        try {
+            return getBuffer(self, littleEndian).getShort(JSType.toInt32(byteOffset));
+        } catch (final IllegalArgumentException iae) {
+            throw rangeError(iae, "dataview.offset");
+        }
+    }
+
+    /**
+     * Get 16-bit signed int from given byteOffset
+     *
+     * @param self DataView object
+     * @param byteOffset byte offset to read from
+     * @return 16-bit signed int value at the byteOffset
+     */
+    @SpecializedFunction
+    public static int getInt16(final Object self, final int byteOffset) {
+        try {
+            return getBuffer(self, false).getShort(byteOffset);
+        } catch (final IllegalArgumentException iae) {
+            throw rangeError(iae, "dataview.offset");
+        }
+    }
+
+    /**
+     * Get 16-bit signed int from given byteOffset
+     *
+     * @param self DataView object
+     * @param byteOffset byte offset to read from
+     * @param littleEndian (optional) flag indicating whether to read in little endian order
+     * @return 16-bit signed int value at the byteOffset
+     */
+    @SpecializedFunction
+    public static int getInt16(final Object self, final int byteOffset, final boolean littleEndian) {
+        try {
+            return getBuffer(self, littleEndian).getShort(byteOffset);
+        } catch (final IllegalArgumentException iae) {
+            throw rangeError(iae, "dataview.offset");
+        }
+    }
+
+    /**
+     * Get 16-bit unsigned int from given byteOffset
+     *
+     * @param self DataView object
+     * @param byteOffset byte offset to read from
+     * @param littleEndian (optional) flag indicating whether to read in little endian order
+     * @return 16-bit unsigned int value at the byteOffset
+     */
+    @Function(attributes = Attribute.NOT_ENUMERABLE, arity = 1)
+    public static int getUint16(final Object self, final Object byteOffset, final Object littleEndian) {
+        try {
+            return 0xFFFF & getBuffer(self, littleEndian).getShort(JSType.toInt32(byteOffset));
+        } catch (final IllegalArgumentException iae) {
+            throw rangeError(iae, "dataview.offset");
+        }
+    }
+
+    /**
+     * Get 16-bit unsigned int from given byteOffset
+     *
+     * @param self DataView object
+     * @param byteOffset byte offset to read from
+     * @return 16-bit unsigned int value at the byteOffset
+     */
+    @SpecializedFunction
+    public static int getUint16(final Object self, final int byteOffset) {
+        try {
+            return 0xFFFF & getBuffer(self, false).getShort(byteOffset);
+        } catch (final IllegalArgumentException iae) {
+            throw rangeError(iae, "dataview.offset");
+        }
+    }
+
+    /**
+     * Get 16-bit unsigned int from given byteOffset
+     *
+     * @param self DataView object
+     * @param byteOffset byte offset to read from
+     * @param littleEndian (optional) flag indicating whether to read in little endian order
+     * @return 16-bit unsigned int value at the byteOffset
+     */
+    @SpecializedFunction
+    public static int getUint16(final Object self, final int byteOffset, final boolean littleEndian) {
+        try {
+            return 0xFFFF & getBuffer(self, littleEndian).getShort(byteOffset);
+        } catch (final IllegalArgumentException iae) {
+            throw rangeError(iae, "dataview.offset");
+        }
+    }
+
+    /**
+     * Get 32-bit signed int from given byteOffset
+     *
+     * @param self DataView object
+     * @param byteOffset byte offset to read from
+     * @param littleEndian (optional) flag indicating whether to read in little endian order
+     * @return 32-bit signed int value at the byteOffset
+     */
+    @Function(attributes = Attribute.NOT_ENUMERABLE, arity = 1)
+    public static int getInt32(final Object self, final Object byteOffset, final Object littleEndian) {
+        try {
+            return getBuffer(self, littleEndian).getInt(JSType.toInt32(byteOffset));
+        } catch (final IllegalArgumentException iae) {
+            throw rangeError(iae, "dataview.offset");
+        }
+    }
+
+    /**
+     * Get 32-bit signed int from given byteOffset
+     *
+     * @param self DataView object
+     * @param byteOffset byte offset to read from
+     * @return 32-bit signed int value at the byteOffset
+     */
+    @SpecializedFunction
+    public static int getInt32(final Object self, final int byteOffset) {
+        try {
+            return getBuffer(self, false).getInt(byteOffset);
+        } catch (final IllegalArgumentException iae) {
+            throw rangeError(iae, "dataview.offset");
+        }
+    }
+
+    /**
+     * Get 32-bit signed int from given byteOffset
+     *
+     * @param self DataView object
+     * @param byteOffset byte offset to read from
+     * @param littleEndian (optional) flag indicating whether to read in little endian order
+     * @return 32-bit signed int value at the byteOffset
+     */
+    @SpecializedFunction
+    public static int getInt32(final Object self, final int byteOffset, final boolean littleEndian) {
+        try {
+            return getBuffer(self, littleEndian).getInt(byteOffset);
+        } catch (final IllegalArgumentException iae) {
+            throw rangeError(iae, "dataview.offset");
+        }
+    }
+
+    /**
+     * Get 32-bit unsigned int from given byteOffset
+     *
+     * @param self DataView object
+     * @param byteOffset byte offset to read from
+     * @param littleEndian (optional) flag indicating whether to read in little endian order
+     * @return 32-bit unsigned int value at the byteOffset
+     */
+    @Function(attributes = Attribute.NOT_ENUMERABLE, arity = 1)
+    public static long getUint32(final Object self, final Object byteOffset, final Object littleEndian) {
+        try {
+            return 0xFFFFFFFFL & getBuffer(self, littleEndian).getInt(JSType.toInt32(byteOffset));
+        } catch (final IllegalArgumentException iae) {
+            throw rangeError(iae, "dataview.offset");
+        }
+    }
+
+    /**
+     * Get 32-bit unsigned int from given byteOffset
+     *
+     * @param self DataView object
+     * @param byteOffset byte offset to read from
+     * @return 32-bit unsigned int value at the byteOffset
+     */
+    @SpecializedFunction
+    public static long getUint32(final Object self, final int byteOffset) {
+        try {
+            return 0xFFFFFFFFL & getBuffer(self, false).getInt(JSType.toInt32(byteOffset));
+        } catch (final IllegalArgumentException iae) {
+            throw rangeError(iae, "dataview.offset");
+        }
+    }
+
+    /**
+     * Get 32-bit unsigned int from given byteOffset
+     *
+     * @param self DataView object
+     * @param byteOffset byte offset to read from
+     * @param littleEndian (optional) flag indicating whether to read in little endian order
+     * @return 32-bit unsigned int value at the byteOffset
+     */
+    @SpecializedFunction
+    public static long getUint32(final Object self, final int byteOffset, final boolean littleEndian) {
+        try {
+            return 0xFFFFFFFFL & getBuffer(self, littleEndian).getInt(JSType.toInt32(byteOffset));
+        } catch (final IllegalArgumentException iae) {
+            throw rangeError(iae, "dataview.offset");
+        }
+    }
+
+    /**
+     * Get 32-bit float value from given byteOffset
+     *
+     * @param self DataView object
+     * @param byteOffset byte offset to read from
+     * @param littleEndian (optional) flag indicating whether to read in little endian order
+     * @return 32-bit float value at the byteOffset
+     */
+    @Function(attributes = Attribute.NOT_ENUMERABLE, arity = 1)
+    public static double getFloat32(final Object self, final Object byteOffset, final Object littleEndian) {
+        try {
+            return getBuffer(self, littleEndian).getFloat(JSType.toInt32(byteOffset));
+        } catch (final IllegalArgumentException iae) {
+            throw rangeError(iae, "dataview.offset");
+        }
+    }
+
+    /**
+     * Get 32-bit float value from given byteOffset
+     *
+     * @param self DataView object
+     * @param byteOffset byte offset to read from
+     * @return 32-bit float value at the byteOffset
+     */
+    @SpecializedFunction
+    public static double getFloat32(final Object self, final int byteOffset) {
+        try {
+            return getBuffer(self, false).getFloat(byteOffset);
+        } catch (final IllegalArgumentException iae) {
+            throw rangeError(iae, "dataview.offset");
+        }
+    }
+
+    /**
+     * Get 32-bit float value from given byteOffset
+     *
+     * @param self DataView object
+     * @param byteOffset byte offset to read from
+     * @param littleEndian (optional) flag indicating whether to read in little endian order
+     * @return 32-bit float value at the byteOffset
+     */
+    @SpecializedFunction
+    public static double getFloat32(final Object self, final int byteOffset, final boolean littleEndian) {
+        try {
+            return getBuffer(self, littleEndian).getFloat(byteOffset);
+        } catch (final IllegalArgumentException iae) {
+            throw rangeError(iae, "dataview.offset");
+        }
+    }
+
+    /**
+     * Get 64-bit float value from given byteOffset
+     *
+     * @param self DataView object
+     * @param byteOffset byte offset to read from
+     * @param littleEndian (optional) flag indicating whether to read in little endian order
+     * @return 64-bit float value at the byteOffset
+     */
+    @Function(attributes = Attribute.NOT_ENUMERABLE, arity = 1)
+    public static double getFloat64(final Object self, final Object byteOffset, final Object littleEndian) {
+        try {
+            return getBuffer(self, littleEndian).getDouble(JSType.toInt32(byteOffset));
+        } catch (final IllegalArgumentException iae) {
+            throw rangeError(iae, "dataview.offset");
+        }
+    }
+
+    /**
+     * Get 64-bit float value from given byteOffset
+     *
+     * @param self DataView object
+     * @param byteOffset byte offset to read from
+     * @return 64-bit float value at the byteOffset
+     */
+    @SpecializedFunction
+    public static double getFloat64(final Object self, final int byteOffset) {
+        try {
+            return getBuffer(self, false).getDouble(byteOffset);
+        } catch (final IllegalArgumentException iae) {
+            throw rangeError(iae, "dataview.offset");
+        }
+    }
+
+    /**
+     * Get 64-bit float value from given byteOffset
+     *
+     * @param self DataView object
+     * @param byteOffset byte offset to read from
+     * @param littleEndian (optional) flag indicating whether to read in little endian order
+     * @return 64-bit float value at the byteOffset
+     */
+    @SpecializedFunction
+    public static double getFloat64(final Object self, final int byteOffset, final boolean littleEndian) {
+        try {
+            return getBuffer(self, littleEndian).getDouble(byteOffset);
+        } catch (final IllegalArgumentException iae) {
+            throw rangeError(iae, "dataview.offset");
+        }
+    }
+
+    // Stores a value of the given type at the specified byte offset
+    // from the start of the view. There is no alignment constraint;
+    // multi-byte values may be stored at any offset.
+    //
+    // For multi-byte values, the optional littleEndian argument
+    // indicates whether the value should be stored in big-endian or
+    // little-endian byte order. If false or undefined, the value is
+    // stored in big-endian byte order.
+    //
+    // These methods raise an exception if they would write
+    // beyond the end of the view.
+
+    /**
+     * Set 8-bit signed int at the given byteOffset
+     *
+     * @param self DataView object
+     * @param byteOffset byte offset to read from
+     * @param value byte value to set
+     * @return undefined
+     */
+    @Function(attributes = Attribute.NOT_ENUMERABLE, arity = 2)
+    public static Object setInt8(final Object self, final Object byteOffset, final Object value) {
+        try {
+            getBuffer(self).put(JSType.toInt32(byteOffset), (byte)JSType.toInt32(value));
+            return UNDEFINED;
+        } catch (final IllegalArgumentException iae) {
+            throw rangeError(iae, "dataview.offset");
+        }
+    }
+
+    /**
+     * Set 8-bit signed int at the given byteOffset
+     *
+     * @param self DataView object
+     * @param byteOffset byte offset to read from
+     * @param value byte value to set
+     * @return undefined
+     */
+    @SpecializedFunction
+    public static Object setInt8(final Object self, final int byteOffset, final int value) {
+        try {
+            getBuffer(self).put(byteOffset, (byte)value);
+            return UNDEFINED;
+        } catch (final IllegalArgumentException iae) {
+            throw rangeError(iae, "dataview.offset");
+        }
+    }
+
+    /**
+     * Set 8-bit unsigned int at the given byteOffset
+     *
+     * @param self DataView object
+     * @param byteOffset byte offset to write at
+     * @param value byte value to set
+     * @return undefined
+     */
+    @Function(attributes = Attribute.NOT_ENUMERABLE, arity = 2)
+    public static Object setUint8(final Object self, final Object byteOffset, final Object value) {
+        try {
+            getBuffer(self).put(JSType.toInt32(byteOffset), (byte)JSType.toInt32(value));
+            return UNDEFINED;
+        } catch (final IllegalArgumentException iae) {
+            throw rangeError(iae, "dataview.offset");
+        }
+    }
+
+    /**
+     * Set 8-bit unsigned int at the given byteOffset
+     *
+     * @param self DataView object
+     * @param byteOffset byte offset to write at
+     * @param value byte value to set
+     * @return undefined
+     */
+    @SpecializedFunction
+    public static Object setUint8(final Object self, final int byteOffset, final int value) {
+        try {
+            getBuffer(self).put(byteOffset, (byte)value);
+            return UNDEFINED;
+        } catch (final IllegalArgumentException iae) {
+            throw rangeError(iae, "dataview.offset");
+        }
+    }
+
+    /**
+     * Set 16-bit signed int at the given byteOffset
+     *
+     * @param self DataView object
+     * @param byteOffset byte offset to write at
+     * @param value short value to set
+     * @param littleEndian (optional) flag indicating whether to write in little endian order
+     * @return undefined
+     */
+    @Function(attributes = Attribute.NOT_ENUMERABLE, arity = 2)
+    public static Object setInt16(final Object self, final Object byteOffset, final Object value, final Object littleEndian) {
+        try {
+            getBuffer(self, littleEndian).putShort(JSType.toInt32(byteOffset), (short)JSType.toInt32(value));
+            return UNDEFINED;
+        } catch (final IllegalArgumentException iae) {
+            throw rangeError(iae, "dataview.offset");
+        }
+    }
+
+    /**
+     * Set 16-bit signed int at the given byteOffset
+     *
+     * @param self DataView object
+     * @param byteOffset byte offset to write at
+     * @param value short value to set
+     * @return undefined
+     */
+    @SpecializedFunction
+    public static Object setInt16(final Object self, final int byteOffset, final int value) {
+        try {
+            getBuffer(self, false).putShort(byteOffset, (short)value);
+            return UNDEFINED;
+        } catch (final IllegalArgumentException iae) {
+            throw rangeError(iae, "dataview.offset");
+        }
+    }
+
+    /**
+     * Set 16-bit signed int at the given byteOffset
+     *
+     * @param self DataView object
+     * @param byteOffset byte offset to write at
+     * @param value short value to set
+     * @param littleEndian (optional) flag indicating whether to write in little endian order
+     * @return undefined
+     */
+    @SpecializedFunction
+    public static Object setInt16(final Object self, final int byteOffset, final int value, final boolean littleEndian) {
+        try {
+            getBuffer(self, littleEndian).putShort(byteOffset, (short)value);
+            return UNDEFINED;
+        } catch (final IllegalArgumentException iae) {
+            throw rangeError(iae, "dataview.offset");
+        }
+    }
+
+    /**
+     * Set 16-bit unsigned int at the given byteOffset
+     *
+     * @param self DataView object
+     * @param byteOffset byte offset to write at
+     * @param value short value to set
+     * @param littleEndian (optional) flag indicating whether to write in little endian order
+     * @return undefined
+     */
+    @Function(attributes = Attribute.NOT_ENUMERABLE, arity = 2)
+    public static Object setUint16(final Object self, final Object byteOffset, final Object value, final Object littleEndian) {
+        try {
+            getBuffer(self, littleEndian).putShort(JSType.toInt32(byteOffset), (short)JSType.toInt32(value));
+            return UNDEFINED;
+        } catch (final IllegalArgumentException iae) {
+            throw rangeError(iae, "dataview.offset");
+        }
+    }
+
+    /**
+     * Set 16-bit unsigned int at the given byteOffset
+     *
+     * @param self DataView object
+     * @param byteOffset byte offset to write at
+     * @param value short value to set
+     * @return undefined
+     */
+    @SpecializedFunction
+    public static Object setUint16(final Object self, final int byteOffset, final int value) {
+        try {
+            getBuffer(self, false).putShort(byteOffset, (short)value);
+            return UNDEFINED;
+        } catch (final IllegalArgumentException iae) {
+            throw rangeError(iae, "dataview.offset");
+        }
+    }
+
+    /**
+     * Set 16-bit unsigned int at the given byteOffset
+     *
+     * @param self DataView object
+     * @param byteOffset byte offset to write at
+     * @param value short value to set
+     * @param littleEndian (optional) flag indicating whether to write in little endian order
+     * @return undefined
+     */
+    @SpecializedFunction
+    public static Object setUint16(final Object self, final int byteOffset, final int value, final boolean littleEndian) {
+        try {
+            getBuffer(self, littleEndian).putShort(byteOffset, (short)value);
+            return UNDEFINED;
+        } catch (final IllegalArgumentException iae) {
+            throw rangeError(iae, "dataview.offset");
+        }
+    }
+
+    /**
+     * Set 32-bit signed int at the given byteOffset
+     *
+     * @param self DataView object
+     * @param byteOffset byte offset to write at
+     * @param value int value to set
+     * @param littleEndian (optional) flag indicating whether to write in little endian order
+     * @return undefined
+     */
+    @Function(attributes = Attribute.NOT_ENUMERABLE, arity = 2)
+    public static Object setInt32(final Object self, final Object byteOffset, final Object value, final Object littleEndian) {
+        try {
+            getBuffer(self, littleEndian).putInt(JSType.toInt32(byteOffset), JSType.toInt32(value));
+            return UNDEFINED;
+        } catch (final IllegalArgumentException iae) {
+            throw rangeError(iae, "dataview.offset");
+        }
+    }
+
+    /**
+     * Set 32-bit signed int at the given byteOffset
+     *
+     * @param self DataView object
+     * @param byteOffset byte offset to write at
+     * @param value int value to set
+     * @return undefined
+     */
+    @SpecializedFunction
+    public static Object setInt32(final Object self, final int byteOffset, final int value) {
+        try {
+            getBuffer(self, false).putInt(byteOffset, value);
+            return UNDEFINED;
+        } catch (final IllegalArgumentException iae) {
+            throw rangeError(iae, "dataview.offset");
+        }
+    }
+
+    /**
+     * Set 32-bit signed int at the given byteOffset
+     *
+     * @param self DataView object
+     * @param byteOffset byte offset to write at
+     * @param value int value to set
+     * @param littleEndian (optional) flag indicating whether to write in little endian order
+     * @return undefined
+     */
+    @SpecializedFunction
+    public static Object setInt32(final Object self, final int byteOffset, final int value, final boolean littleEndian) {
+        try {
+            getBuffer(self, littleEndian).putInt(byteOffset, value);
+            return UNDEFINED;
+        } catch (final IllegalArgumentException iae) {
+            throw rangeError(iae, "dataview.offset");
+        }
+    }
+
+    /**
+     * Set 32-bit unsigned int at the given byteOffset
+     *
+     * @param self DataView object
+     * @param byteOffset byte offset to write at
+     * @param value int value to set
+     * @param littleEndian (optional) flag indicating whether to write in little endian order
+     * @return undefined
+     */
+    @Function(attributes = Attribute.NOT_ENUMERABLE, arity = 2)
+    public static Object setUint32(final Object self, final Object byteOffset, final Object value, final Object littleEndian) {
+        try {
+            getBuffer(self, littleEndian).putInt(JSType.toInt32(byteOffset), (int)JSType.toUint32(value));
+            return UNDEFINED;
+        } catch (final IllegalArgumentException iae) {
+            throw rangeError(iae, "dataview.offset");
+        }
+    }
+
+    /**
+     * Set 32-bit unsigned int at the given byteOffset
+     *
+     * @param self DataView object
+     * @param byteOffset byte offset to write at
+     * @param value int value to set
+     * @return undefined
+     */
+    @SpecializedFunction
+    public static Object setUint32(final Object self, final int byteOffset, final long value) {
+        try {
+            getBuffer(self, false).putInt(byteOffset, (int)value);
+            return UNDEFINED;
+        } catch (final IllegalArgumentException iae) {
+            throw rangeError(iae, "dataview.offset");
+        }
+    }
+
+    /**
+     * Set 32-bit unsigned int at the given byteOffset
+     *
+     * @param self DataView object
+     * @param byteOffset byte offset to write at
+     * @param value int value to set
+     * @param littleEndian (optional) flag indicating whether to write in little endian order
+     * @return undefined
+     */
+    @SpecializedFunction
+    public static Object setUint32(final Object self, final int byteOffset, final long value, final boolean littleEndian) {
+        try {
+            getBuffer(self, littleEndian).putInt(byteOffset, (int)value);
+            return UNDEFINED;
+        } catch (final IllegalArgumentException iae) {
+            throw rangeError(iae, "dataview.offset");
+        }
+    }
+
+    /**
+     * Set 32-bit float at the given byteOffset
+     *
+     * @param self DataView object
+     * @param byteOffset byte offset to write at
+     * @param value float value to set
+     * @param littleEndian (optional) flag indicating whether to write in little endian order
+     * @return undefined
+     */
+    @Function(attributes = Attribute.NOT_ENUMERABLE, arity = 2)
+    public static Object setFloat32(final Object self, final Object byteOffset, final Object value, final Object littleEndian) {
+        try {
+            getBuffer(self, littleEndian).putFloat((int)JSType.toUint32(byteOffset), (float)JSType.toNumber(value));
+            return UNDEFINED;
+        } catch (final IllegalArgumentException iae) {
+            throw rangeError(iae, "dataview.offset");
+        }
+    }
+
+    /**
+     * Set 32-bit float at the given byteOffset
+     *
+     * @param self DataView object
+     * @param byteOffset byte offset to write at
+     * @param value float value to set
+     * @return undefined
+     */
+    @SpecializedFunction
+    public static Object setFloat32(final Object self, final int byteOffset, final double value) {
+        try {
+            getBuffer(self, false).putFloat(byteOffset, (float)value);
+            return UNDEFINED;
+        } catch (final IllegalArgumentException iae) {
+            throw rangeError(iae, "dataview.offset");
+        }
+    }
+
+    /**
+     * Set 32-bit float at the given byteOffset
+     *
+     * @param self DataView object
+     * @param byteOffset byte offset to write at
+     * @param value float value to set
+     * @param littleEndian (optional) flag indicating whether to write in little endian order
+     * @return undefined
+     */
+    @SpecializedFunction
+    public static Object setFloat32(final Object self, final int byteOffset, final double value, final boolean littleEndian) {
+        try {
+            getBuffer(self, littleEndian).putFloat(byteOffset, (float)value);
+            return UNDEFINED;
+        } catch (final IllegalArgumentException iae) {
+            throw rangeError(iae, "dataview.offset");
+        }
+    }
+
+    /**
+     * Set 64-bit float at the given byteOffset
+     *
+     * @param self DataView object
+     * @param byteOffset byte offset to write at
+     * @param value double value to set
+     * @param littleEndian (optional) flag indicating whether to write in little endian order
+     * @return undefined
+     */
+    @Function(attributes = Attribute.NOT_ENUMERABLE, arity = 2)
+    public static Object setFloat64(final Object self, final Object byteOffset, final Object value, final Object littleEndian) {
+        try {
+            getBuffer(self, littleEndian).putDouble((int)JSType.toUint32(byteOffset), JSType.toNumber(value));
+            return UNDEFINED;
+        } catch (final IllegalArgumentException iae) {
+            throw rangeError(iae, "dataview.offset");
+        }
+    }
+
+    /**
+     * Set 64-bit float at the given byteOffset
+     *
+     * @param self DataView object
+     * @param byteOffset byte offset to write at
+     * @param value double value to set
+     * @return undefined
+     */
+    @SpecializedFunction
+    public static Object setFloat64(final Object self, final int byteOffset, final double value) {
+        try {
+            getBuffer(self, false).putDouble(byteOffset, value);
+            return UNDEFINED;
+        } catch (final IllegalArgumentException iae) {
+            throw rangeError(iae, "dataview.offset");
+        }
+    }
+
+    /**
+     * Set 64-bit float at the given byteOffset
+     *
+     * @param self DataView object
+     * @param byteOffset byte offset to write at
+     * @param value double value to set
+     * @param littleEndian (optional) flag indicating whether to write in little endian order
+     * @return undefined
+     */
+    @SpecializedFunction
+    public static Object setFloat64(final Object self, final int byteOffset, final double value, final boolean littleEndian) {
+        try {
+            getBuffer(self, littleEndian).putDouble(byteOffset, value);
+            return UNDEFINED;
+        } catch (final IllegalArgumentException iae) {
+            throw rangeError(iae, "dataview.offset");
+        }
+    }
+
+    // internals only below this point
+    private static ByteBuffer bufferFrom(final NativeArrayBuffer nab, final int offset) {
+        try {
+            return nab.getBuffer(offset);
+        } catch (final IllegalArgumentException iae) {
+            throw rangeError(iae, "dataview.constructor.offset");
+        }
+    }
+
+    private static ByteBuffer bufferFrom(final NativeArrayBuffer nab, final int offset, final int length) {
+        try {
+            return nab.getBuffer(offset, length);
+        } catch (final IllegalArgumentException iae) {
+            throw rangeError(iae, "dataview.constructor.offset");
+        }
+    }
+
+    private static NativeDataView checkSelf(final Object self) {
+        if (!(self instanceof NativeDataView)) {
+            throw typeError("not.an.arraybuffer", ScriptRuntime.safeToString(self));
+        }
+        return (NativeDataView)self;
+    }
+
+    private static ByteBuffer getBuffer(final Object self) {
+        return checkSelf(self).buf;
+    }
+
+    private static ByteBuffer getBuffer(final Object self, final Object littleEndian) {
+        return getBuffer(self, JSType.toBoolean(littleEndian));
+    }
+
+    private static ByteBuffer getBuffer(final Object self, final boolean littleEndian) {
+        return getBuffer(self).order(littleEndian? ByteOrder.LITTLE_ENDIAN : ByteOrder.BIG_ENDIAN);
+    }
+}
--- a/src/jdk/nashorn/internal/objects/NativeDate.java	Thu Mar 20 16:26:54 2014 +0100
+++ b/src/jdk/nashorn/internal/objects/NativeDate.java	Fri Mar 21 17:52:03 2014 +0100
@@ -114,10 +114,6 @@
     // initialized by nasgen
     private static PropertyMap $nasgenmap$;
 
-    static PropertyMap getInitialMap() {
-        return $nasgenmap$;
-    }
-
     private NativeDate(final double time, final ScriptObject proto, final PropertyMap map) {
         super(proto, map);
         final ScriptEnvironment env = Global.getEnv();
@@ -127,7 +123,7 @@
     }
 
     NativeDate(final double time, final Global global) {
-        this(time, global.getDatePrototype(), global.getDateMap());
+        this(time, global.getDatePrototype(), $nasgenmap$);
     }
 
     private NativeDate (final double time) {
--- a/src/jdk/nashorn/internal/objects/NativeDebug.java	Thu Mar 20 16:26:54 2014 +0100
+++ b/src/jdk/nashorn/internal/objects/NativeDebug.java	Fri Mar 21 17:52:03 2014 +0100
@@ -34,7 +34,7 @@
 import jdk.nashorn.internal.objects.annotations.ScriptClass;
 import jdk.nashorn.internal.objects.annotations.Where;
 import jdk.nashorn.internal.runtime.Context;
-import jdk.nashorn.internal.runtime.PropertyListenerManager;
+import jdk.nashorn.internal.runtime.PropertyListeners;
 import jdk.nashorn.internal.runtime.PropertyMap;
 import jdk.nashorn.internal.runtime.ScriptFunction;
 import jdk.nashorn.internal.runtime.ScriptObject;
@@ -196,7 +196,7 @@
      */
     @Function(attributes = Attribute.NOT_ENUMERABLE, where = Where.CONSTRUCTOR)
     public static Object getListenerCount(final Object self, final Object obj) {
-        return (obj instanceof ScriptObject)? ((ScriptObject)obj).getListenerCount() : 0;
+        return (obj instanceof ScriptObject) ? PropertyListeners.getListenerCount((ScriptObject) obj) : 0;
     }
 
     /**
@@ -213,14 +213,13 @@
 
         out.println("ScriptObject count " + ScriptObject.getCount());
         out.println("Scope count " + ScriptObject.getScopeCount());
-        out.println("ScriptObject listeners added " + PropertyListenerManager.getListenersAdded());
-        out.println("ScriptObject listeners removed " + PropertyListenerManager.getListenersRemoved());
+        out.println("ScriptObject listeners added " + PropertyListeners.getListenersAdded());
+        out.println("ScriptObject listeners removed " + PropertyListeners.getListenersRemoved());
         out.println("ScriptFunction constructor calls " + ScriptFunction.getConstructorCount());
         out.println("ScriptFunction invokes " + ScriptFunction.getInvokes());
         out.println("ScriptFunction allocations " + ScriptFunction.getAllocations());
         out.println("PropertyMap count " + PropertyMap.getCount());
         out.println("PropertyMap cloned " + PropertyMap.getClonedCount());
-        out.println("PropertyMap shared " + PropertyMap.getSharedCount());
         out.println("PropertyMap duplicated " + PropertyMap.getDuplicatedCount());
         out.println("PropertyMap history hit " + PropertyMap.getHistoryHit());
         out.println("PropertyMap proto invalidations " + PropertyMap.getProtoInvalidations());
--- a/src/jdk/nashorn/internal/objects/NativeError.java	Thu Mar 20 16:26:54 2014 +0100
+++ b/src/jdk/nashorn/internal/objects/NativeError.java	Fri Mar 21 17:52:03 2014 +0100
@@ -92,10 +92,6 @@
     // initialized by nasgen
     private static PropertyMap $nasgenmap$;
 
-    static PropertyMap getInitialMap() {
-        return $nasgenmap$;
-    }
-
     @SuppressWarnings("LeakingThisInConstructor")
     private NativeError(final Object msg, final ScriptObject proto, final PropertyMap map) {
         super(proto, map);
@@ -108,7 +104,7 @@
     }
 
     NativeError(final Object msg, final Global global) {
-        this(msg, global.getErrorPrototype(), global.getErrorMap());
+        this(msg, global.getErrorPrototype(), $nasgenmap$);
     }
 
     private NativeError(final Object msg) {
--- a/src/jdk/nashorn/internal/objects/NativeEvalError.java	Thu Mar 20 16:26:54 2014 +0100
+++ b/src/jdk/nashorn/internal/objects/NativeEvalError.java	Fri Mar 21 17:52:03 2014 +0100
@@ -62,10 +62,6 @@
     // initialized by nasgen
     private static PropertyMap $nasgenmap$;
 
-    static PropertyMap getInitialMap() {
-        return $nasgenmap$;
-    }
-
     @SuppressWarnings("LeakingThisInConstructor")
     private NativeEvalError(final Object msg, final ScriptObject proto, final PropertyMap map) {
         super(proto, map);
@@ -78,7 +74,7 @@
     }
 
     NativeEvalError(final Object msg, final Global global) {
-        this(msg, global.getEvalErrorPrototype(), global.getEvalErrorMap());
+        this(msg, global.getEvalErrorPrototype(), $nasgenmap$);
     }
 
     private NativeEvalError(final Object msg) {
--- a/src/jdk/nashorn/internal/objects/NativeJSAdapter.java	Thu Mar 20 16:26:54 2014 +0100
+++ b/src/jdk/nashorn/internal/objects/NativeJSAdapter.java	Fri Mar 21 17:52:03 2014 +0100
@@ -147,10 +147,6 @@
     // initialized by nasgen
     private static PropertyMap $nasgenmap$;
 
-    static PropertyMap getInitialMap() {
-        return $nasgenmap$;
-    }
-
     NativeJSAdapter(final Object overrides, final ScriptObject adaptee, final ScriptObject proto, final PropertyMap map) {
         super(proto, map);
         this.adaptee = wrapAdaptee(adaptee);
@@ -164,7 +160,7 @@
     }
 
     private static ScriptObject wrapAdaptee(final ScriptObject adaptee) {
-        return new JO(adaptee, Global.instance().getObjectMap());
+        return new JO(adaptee, JO.getInitialMap());
     }
 
     @Override
@@ -578,7 +574,7 @@
             proto = global.getJSAdapterPrototype();
         }
 
-        return new NativeJSAdapter(overrides, (ScriptObject)adaptee, (ScriptObject)proto, global.getJSAdapterMap());
+        return new NativeJSAdapter(overrides, (ScriptObject)adaptee, (ScriptObject)proto, $nasgenmap$);
     }
 
     @Override
@@ -623,7 +619,7 @@
         case "getMethod":
             final FindProperty find = adaptee.findProperty(__call__, true);
             if (find != null) {
-                final Object value = getObjectValue(find);
+                final Object value = find.getObjectValue();
                 if (value instanceof ScriptFunction) {
                     final ScriptFunctionImpl func = (ScriptFunctionImpl)value;
                     // TODO: It's a shame we need to produce a function bound to this and name, when we'd only need it bound
@@ -631,7 +627,7 @@
                     return new GuardedInvocation(MH.dropArguments(MH.constant(Object.class,
                             func.makeBoundFunction(this, new Object[] { name })), 0, Object.class),
                             testJSAdaptor(adaptee, null, null, null),
-                            adaptee.getMap().getProtoGetSwitchPoint(adaptee.getProto(), __call__));
+                            adaptee.getProtoSwitchPoint(__call__, find.getOwner()));
                 }
             }
             throw typeError("no.such.function", desc.getNameToken(2), ScriptRuntime.safeToString(this));
@@ -692,7 +688,7 @@
         final MethodType type = desc.getMethodType();
         if (findData != null) {
             final String name = desc.getNameTokenCount() > 2 ? desc.getNameToken(2) : null;
-            final Object value = getObjectValue(findData);
+            final Object value = findData.getObjectValue();
             if (value instanceof ScriptFunction) {
                 final ScriptFunction func = (ScriptFunction)value;
 
@@ -702,7 +698,7 @@
                     return new GuardedInvocation(
                             methodHandle,
                             testJSAdaptor(adaptee, findData.getGetter(Object.class, UnwarrantedOptimismException.INVALID_PROGRAM_POINT), findData.getOwner(), func),
-                            adaptee.getMap().getProtoGetSwitchPoint(adaptee.getProto(), hook));
+                            adaptee.getProtoSwitchPoint(hook, findData.getOwner()));
                 }
              }
         }
@@ -714,7 +710,7 @@
             final MethodHandle methodHandle = hook.equals(__put__) ?
             MH.asType(Lookup.EMPTY_SETTER, type) :
             Lookup.emptyGetter(type.returnType());
-            return new GuardedInvocation(methodHandle, testJSAdaptor(adaptee, null, null, null), adaptee.getMap().getProtoGetSwitchPoint(adaptee.getProto(), hook));
+            return new GuardedInvocation(methodHandle, testJSAdaptor(adaptee, null, null, null), adaptee.getProtoSwitchPoint(hook, null));
         }
     }
 
--- a/src/jdk/nashorn/internal/objects/NativeJavaImporter.java	Thu Mar 20 16:26:54 2014 +0100
+++ b/src/jdk/nashorn/internal/objects/NativeJavaImporter.java	Fri Mar 21 17:52:03 2014 +0100
@@ -63,17 +63,13 @@
     // initialized by nasgen
     private static PropertyMap $nasgenmap$;
 
-    static PropertyMap getInitialMap() {
-        return $nasgenmap$;
-    }
-
     private NativeJavaImporter(final Object[] args, final ScriptObject proto, final PropertyMap map) {
         super(proto, map);
         this.args = args;
     }
 
     private NativeJavaImporter(final Object[] args, final Global global) {
-        this(args, global.getJavaImporterPrototype(), global.getJavaImporterMap());
+        this(args, global.getJavaImporterPrototype(), $nasgenmap$);
     }
 
     private NativeJavaImporter(final Object[] args) {
--- a/src/jdk/nashorn/internal/objects/NativeNumber.java	Thu Mar 20 16:26:54 2014 +0100
+++ b/src/jdk/nashorn/internal/objects/NativeNumber.java	Fri Mar 21 17:52:03 2014 +0100
@@ -32,6 +32,7 @@
 
 import java.lang.invoke.MethodHandle;
 import java.lang.invoke.MethodHandles;
+import java.lang.invoke.MethodType;
 import java.text.NumberFormat;
 import java.util.Locale;
 import jdk.internal.dynalink.linker.GuardedInvocation;
@@ -56,7 +57,10 @@
 @ScriptClass("Number")
 public final class NativeNumber extends ScriptObject {
 
-    static final MethodHandle WRAPFILTER = findWrapFilter();
+    // Method handle to create an object wrapper for a primitive number
+    private static final MethodHandle WRAPFILTER = findOwnMH("wrapFilter", MH.type(NativeNumber.class, Object.class));
+    // Method handle to retrieve the Number prototype object
+    private static final MethodHandle PROTOFILTER = findOwnMH("protoFilter", MH.type(Object.class, Object.class));
 
     /** ECMA 15.7.3.2 largest positive finite value */
     @Property(attributes = Attribute.NON_ENUMERABLE_CONSTANT, where = Where.CONSTRUCTOR)
@@ -83,17 +87,13 @@
     // initialized by nasgen
     private static PropertyMap $nasgenmap$;
 
-    static PropertyMap getInitialMap() {
-        return $nasgenmap$;
-    }
-
     private NativeNumber(final double value, final ScriptObject proto, final PropertyMap map) {
         super(proto, map);
         this.value = value;
     }
 
     NativeNumber(final double value, final Global global) {
-        this(value, global.getNumberPrototype(), global.getNumberMap());
+        this(value, global.getNumberPrototype(), $nasgenmap$);
     }
 
     private NativeNumber(final double value) {
@@ -320,7 +320,7 @@
      * @return Link to be invoked at call site.
      */
     public static GuardedInvocation lookupPrimitive(final LinkRequest request, final Object receiver) {
-        return PrimitiveLookup.lookupPrimitive(request, Number.class, new NativeNumber(((Number)receiver).doubleValue()), WRAPFILTER);
+        return PrimitiveLookup.lookupPrimitive(request, Number.class, new NativeNumber(((Number)receiver).doubleValue()), WRAPFILTER, PROTOFILTER);
     }
 
     @SuppressWarnings("unused")
@@ -328,6 +328,11 @@
         return new NativeNumber(((Number)receiver).doubleValue());
     }
 
+    @SuppressWarnings("unused")
+    private static Object protoFilter(final Object object) {
+        return Global.instance().getNumberPrototype();
+    }
+
     private static double getNumberValue(final Object self) {
         if (self instanceof Number) {
             return ((Number)self).doubleValue();
@@ -376,7 +381,7 @@
         return str;
     }
 
-    private static MethodHandle findWrapFilter() {
-        return MH.findStatic(MethodHandles.lookup(), NativeNumber.class, "wrapFilter", MH.type(NativeNumber.class, Object.class));
+    private static MethodHandle findOwnMH(final String name, final MethodType type) {
+        return MH.findStatic(MethodHandles.lookup(), NativeNumber.class, name, type);
     }
 }
--- a/src/jdk/nashorn/internal/objects/NativeRangeError.java	Thu Mar 20 16:26:54 2014 +0100
+++ b/src/jdk/nashorn/internal/objects/NativeRangeError.java	Fri Mar 21 17:52:03 2014 +0100
@@ -62,10 +62,6 @@
     // initialized by nasgen
     private static PropertyMap $nasgenmap$;
 
-    static PropertyMap getInitialMap() {
-        return $nasgenmap$;
-    }
-
     @SuppressWarnings("LeakingThisInConstructor")
     private NativeRangeError(final Object msg, final ScriptObject proto, final PropertyMap map) {
         super(proto, map);
@@ -78,7 +74,7 @@
     }
 
     NativeRangeError(final Object msg, final Global global) {
-        this(msg, global.getRangeErrorPrototype(), global.getRangeErrorMap());
+        this(msg, global.getRangeErrorPrototype(), $nasgenmap$);
     }
 
     private NativeRangeError(final Object msg) {
--- a/src/jdk/nashorn/internal/objects/NativeReferenceError.java	Thu Mar 20 16:26:54 2014 +0100
+++ b/src/jdk/nashorn/internal/objects/NativeReferenceError.java	Fri Mar 21 17:52:03 2014 +0100
@@ -62,10 +62,6 @@
     // initialized by nasgen
     private static PropertyMap $nasgenmap$;
 
-    static PropertyMap getInitialMap() {
-        return $nasgenmap$;
-    }
-
     @SuppressWarnings("LeakingThisInConstructor")
     private NativeReferenceError(final Object msg, final ScriptObject proto, final PropertyMap map) {
         super(proto, map);
@@ -78,7 +74,7 @@
     }
 
     NativeReferenceError(final Object msg, final Global global) {
-        this(msg, global.getReferenceErrorPrototype(), global.getReferenceErrorMap());
+        this(msg, global.getReferenceErrorPrototype(), $nasgenmap$);
     }
 
     private NativeReferenceError(final Object msg) {
--- a/src/jdk/nashorn/internal/objects/NativeRegExp.java	Thu Mar 20 16:26:54 2014 +0100
+++ b/src/jdk/nashorn/internal/objects/NativeRegExp.java	Fri Mar 21 17:52:03 2014 +0100
@@ -72,12 +72,8 @@
     // initialized by nasgen
     private static PropertyMap $nasgenmap$;
 
-    static PropertyMap getInitialMap() {
-        return $nasgenmap$;
-    }
-
     private NativeRegExp(final Global global) {
-        super(global.getRegExpPrototype(), global.getRegExpMap());
+        super(global.getRegExpPrototype(), $nasgenmap$);
         this.globalObject = global;
     }
 
--- a/src/jdk/nashorn/internal/objects/NativeRegExpExecResult.java	Thu Mar 20 16:26:54 2014 +0100
+++ b/src/jdk/nashorn/internal/objects/NativeRegExpExecResult.java	Fri Mar 21 17:52:03 2014 +0100
@@ -53,12 +53,8 @@
     // initialized by nasgen
     private static PropertyMap $nasgenmap$;
 
-    static PropertyMap getInitialMap() {
-        return $nasgenmap$;
-    }
-
     NativeRegExpExecResult(final RegExpResult result, final Global global) {
-        super(global.getArrayPrototype(), global.getRegExpExecResultMap());
+        super(global.getArrayPrototype(), $nasgenmap$);
         setIsArray();
         this.setArray(ArrayData.allocate(result.getGroups().clone()));
         this.index = result.getIndex();
--- a/src/jdk/nashorn/internal/objects/NativeStrictArguments.java	Thu Mar 20 16:26:54 2014 +0100
+++ b/src/jdk/nashorn/internal/objects/NativeStrictArguments.java	Fri Mar 21 17:52:03 2014 +0100
@@ -60,9 +60,9 @@
         // In strict mode, the caller and callee properties should throw TypeError
         // Need to add properties directly to map since slots are assigned speculatively by newUserAccessors.
         final int flags = Property.NOT_ENUMERABLE | Property.NOT_CONFIGURABLE;
-        map = map.addProperty(map.newUserAccessors("caller", flags));
-        map = map.addProperty(map.newUserAccessors("callee", flags));
-        map$ = map.setIsShared();
+        map = map.addPropertyNoHistory(map.newUserAccessors("caller", flags));
+        map = map.addPropertyNoHistory(map.newUserAccessors("callee", flags));
+        map$ = map;
     }
 
     static PropertyMap getInitialMap() {
--- a/src/jdk/nashorn/internal/objects/NativeString.java	Thu Mar 20 16:26:54 2014 +0100
+++ b/src/jdk/nashorn/internal/objects/NativeString.java	Fri Mar 21 17:52:03 2014 +0100
@@ -32,6 +32,7 @@
 
 import java.lang.invoke.MethodHandle;
 import java.lang.invoke.MethodHandles;
+import java.lang.invoke.MethodType;
 import java.text.Collator;
 import java.util.ArrayList;
 import java.util.Arrays;
@@ -69,21 +70,20 @@
 
     private final CharSequence value;
 
-    static final MethodHandle WRAPFILTER = findWrapFilter();
+    // Method handle to create an object wrapper for a primitive string
+    private static final MethodHandle WRAPFILTER = findOwnMH("wrapFilter", MH.type(NativeString.class, Object.class));
+    // Method handle to retrieve the String prototype object
+    private static final MethodHandle PROTOFILTER = findOwnMH("protoFilter", MH.type(Object.class, Object.class));
 
     // initialized by nasgen
     private static PropertyMap $nasgenmap$;
 
-    static PropertyMap getInitialMap() {
-        return $nasgenmap$;
-    }
-
     private NativeString(final CharSequence value) {
         this(value, Global.instance());
     }
 
     NativeString(final CharSequence value, final Global global) {
-        this(value, global.getStringPrototype(), global.getStringMap());
+        this(value, global.getStringPrototype(), $nasgenmap$);
     }
 
     private NativeString(final CharSequence value, final ScriptObject proto, final PropertyMap map) {
@@ -1243,7 +1243,7 @@
      */
     public static GuardedInvocation lookupPrimitive(final LinkRequest request, final Object receiver) {
         final MethodHandle guard = NashornGuards.getInstanceOf2Guard(String.class, ConsString.class);
-        return PrimitiveLookup.lookupPrimitive(request, guard, new NativeString((CharSequence)receiver), WRAPFILTER);
+        return PrimitiveLookup.lookupPrimitive(request, guard, new NativeString((CharSequence)receiver), WRAPFILTER, PROTOFILTER);
     }
 
     @SuppressWarnings("unused")
@@ -1251,6 +1251,11 @@
         return new NativeString((CharSequence)receiver);
     }
 
+    @SuppressWarnings("unused")
+    private static Object protoFilter(final Object object) {
+        return Global.instance().getStringPrototype();
+    }
+
     private static CharSequence getCharSequence(final Object self) {
         if (self instanceof String || self instanceof ConsString) {
             return (CharSequence)self;
@@ -1298,8 +1303,8 @@
         return key >= 0 && key < value.length();
     }
 
-    private static MethodHandle findWrapFilter() {
-        return MH.findStatic(MethodHandles.lookup(), NativeString.class, "wrapFilter", MH.type(NativeString.class, Object.class));
+    private static MethodHandle findOwnMH(final String name, final MethodType type) {
+        return MH.findStatic(MethodHandles.lookup(), NativeString.class, name, type);
     }
 
 }
--- a/src/jdk/nashorn/internal/objects/NativeSyntaxError.java	Thu Mar 20 16:26:54 2014 +0100
+++ b/src/jdk/nashorn/internal/objects/NativeSyntaxError.java	Fri Mar 21 17:52:03 2014 +0100
@@ -62,13 +62,9 @@
     // initialized by nasgen
     private static PropertyMap $nasgenmap$;
 
-    static PropertyMap getInitialMap() {
-        return $nasgenmap$;
-    }
-
     @SuppressWarnings("LeakingThisInConstructor")
     NativeSyntaxError(final Object msg, final Global global) {
-        super(global.getSyntaxErrorPrototype(), global.getSyntaxErrorMap());
+        super(global.getSyntaxErrorPrototype(), $nasgenmap$);
         if (msg != UNDEFINED) {
             this.instMessage = JSType.toString(msg);
         } else {
--- a/src/jdk/nashorn/internal/objects/NativeTypeError.java	Thu Mar 20 16:26:54 2014 +0100
+++ b/src/jdk/nashorn/internal/objects/NativeTypeError.java	Fri Mar 21 17:52:03 2014 +0100
@@ -62,13 +62,9 @@
     // initialized by nasgen
     private static PropertyMap $nasgenmap$;
 
-    static PropertyMap getInitialMap() {
-        return $nasgenmap$;
-    }
-
     @SuppressWarnings("LeakingThisInConstructor")
     NativeTypeError(final Object msg, final Global global) {
-        super(global.getTypeErrorPrototype(), global.getTypeErrorMap());
+        super(global.getTypeErrorPrototype(), $nasgenmap$);
         if (msg != UNDEFINED) {
             this.instMessage = JSType.toString(msg);
         } else {
--- a/src/jdk/nashorn/internal/objects/NativeURIError.java	Thu Mar 20 16:26:54 2014 +0100
+++ b/src/jdk/nashorn/internal/objects/NativeURIError.java	Fri Mar 21 17:52:03 2014 +0100
@@ -61,13 +61,9 @@
     // initialized by nasgen
     private static PropertyMap $nasgenmap$;
 
-    static PropertyMap getInitialMap() {
-        return $nasgenmap$;
-    }
-
     @SuppressWarnings("LeakingThisInConstructor")
     NativeURIError(final Object msg, final Global global) {
-        super(global.getURIErrorPrototype(), global.getURIErrorMap());
+        super(global.getURIErrorPrototype(), $nasgenmap$);
         if (msg != UNDEFINED) {
             this.instMessage = JSType.toString(msg);
         } else {
--- a/src/jdk/nashorn/internal/objects/PrototypeObject.java	Thu Mar 20 16:26:54 2014 +0100
+++ b/src/jdk/nashorn/internal/objects/PrototypeObject.java	Fri Mar 21 17:52:03 2014 +0100
@@ -54,16 +54,11 @@
     static {
         final ArrayList<Property> properties = new ArrayList<>(1);
         properties.add(AccessorProperty.create("constructor", Property.NOT_ENUMERABLE, GET_CONSTRUCTOR, SET_CONSTRUCTOR));
-        map$ = PropertyMap.newMap(properties).setIsShared();
-    }
-
-    static PropertyMap getInitialMap() {
-        return map$;
+        map$ = PropertyMap.newMap(properties);
     }
 
     private PrototypeObject(final Global global, final PropertyMap map) {
-        super(map != map$? map.addAll(global.getPrototypeObjectMap()) : global.getPrototypeObjectMap());
-        setProto(global.getObjectPrototype());
+        super(global.getObjectPrototype(), map != map$? map.addAll(map$) : map$);
     }
 
     PrototypeObject() {
--- a/src/jdk/nashorn/internal/objects/ScriptFunctionImpl.java	Thu Mar 20 16:26:54 2014 +0100
+++ b/src/jdk/nashorn/internal/objects/ScriptFunctionImpl.java	Fri Mar 21 17:52:03 2014 +0100
@@ -55,27 +55,11 @@
     // property map for non-strict, non-bound functions.
     private static final PropertyMap map$;
 
-    static PropertyMap getInitialMap() {
-        return map$;
-    }
-
-    static PropertyMap getInitialAnonymousMap() {
-        return AnonymousFunction.getInitialMap();
-    }
-
-    static PropertyMap getInitialStrictMap() {
-        return strictmodemap$;
-    }
-
-    static PropertyMap getInitialBoundMap() {
-        return boundfunctionmap$;
-    }
-
     // Marker object for lazily initialized prototype object
     private static final Object LAZY_PROTOTYPE = new Object();
 
     private ScriptFunctionImpl(final String name, final MethodHandle invokeHandle, final MethodHandle[] specs, final Global global) {
-        super(name, invokeHandle, global.getFunctionMap(), null, specs, false, true, true);
+        super(name, invokeHandle, map$, null, specs, ScriptFunctionData.IS_BUILTIN_CONSTRUCTOR);
         init(global);
     }
 
@@ -92,7 +76,7 @@
     }
 
     private ScriptFunctionImpl(final String name, final MethodHandle invokeHandle, final PropertyMap map, final MethodHandle[] specs, final Global global) {
-        super(name, invokeHandle, map.addAll(global.getFunctionMap()), null, specs, false, true, true);
+        super(name, invokeHandle, map.addAll(map$), null, specs, ScriptFunctionData.IS_BUILTIN_CONSTRUCTOR);
         init(global);
     }
 
@@ -109,8 +93,8 @@
         this(name, invokeHandle, map, specs, Global.instance());
     }
 
-    private ScriptFunctionImpl(final String name, final MethodHandle methodHandle, final ScriptObject scope, final MethodHandle[] specs, final boolean isStrict, final boolean isBuiltin, final boolean isConstructor, final Global global) {
-        super(name, methodHandle, getMap(global, isStrict), scope, specs, isStrict, isBuiltin, isConstructor);
+    private ScriptFunctionImpl(final String name, final MethodHandle methodHandle, final ScriptObject scope, final MethodHandle[] specs, final int flags, final Global global) {
+        super(name, methodHandle, getMap(isStrict(flags)), scope, specs, flags);
         init(global);
     }
 
@@ -121,16 +105,14 @@
      * @param methodHandle handle for invocation
      * @param scope scope object
      * @param specs specialized versions of this method, if available, null otherwise
-     * @param isStrict are we in strict mode
-     * @param isBuiltin is this a built-in function
-     * @param isConstructor can the function be used as a constructor (most can; some built-ins are restricted).
+     * @param flags {@link ScriptFunctionData} flags
      */
-    ScriptFunctionImpl(final String name, final MethodHandle methodHandle, final ScriptObject scope, final MethodHandle[] specs, final boolean isStrict, final boolean isBuiltin, final boolean isConstructor) {
-        this(name, methodHandle, scope, specs, isStrict, isBuiltin, isConstructor, Global.instance());
+    ScriptFunctionImpl(final String name, final MethodHandle methodHandle, final ScriptObject scope, final MethodHandle[] specs, final int flags) {
+        this(name, methodHandle, scope, specs, flags, Global.instance());
     }
 
     private ScriptFunctionImpl(final RecompilableScriptFunctionData data, final ScriptObject scope, final Global global) {
-        super(data, getMap(global, data.isStrict()), scope);
+        super(data, getMap(data.isStrict()), scope);
         init(global);
     }
 
@@ -150,7 +132,7 @@
      * @param global the global object
      */
     ScriptFunctionImpl(final ScriptFunctionData data, final Global global) {
-        super(data, global.getBoundFunctionMap(), null);
+        super(data, boundfunctionmap$, null);
         init(global);
     }
 
@@ -162,25 +144,24 @@
         map$ = PropertyMap.newMap(properties);
         strictmodemap$ = createStrictModeMap(map$);
         boundfunctionmap$ = createBoundFunctionMap(strictmodemap$);
-        // There are order dependencies between normal map, struct map and bound map
-        // We can make these 'shared' only after initialization of all three.
-        map$.setIsShared();
-        strictmodemap$.setIsShared();
-        boundfunctionmap$.setIsShared();
     }
 
     private static PropertyMap createStrictModeMap(final PropertyMap map) {
         final int flags = Property.NOT_ENUMERABLE | Property.NOT_CONFIGURABLE;
         PropertyMap newMap = map;
         // Need to add properties directly to map since slots are assigned speculatively by newUserAccessors.
-        newMap = newMap.addProperty(map.newUserAccessors("arguments", flags));
-        newMap = newMap.addProperty(map.newUserAccessors("caller", flags));
+        newMap = newMap.addPropertyNoHistory(map.newUserAccessors("arguments", flags));
+        newMap = newMap.addPropertyNoHistory(map.newUserAccessors("caller", flags));
         return newMap;
     }
 
+    private static boolean isStrict(final int flags) {
+        return (flags & ScriptFunctionData.IS_STRICT) != 0;
+    }
+
     // Choose the map based on strict mode!
-    private static PropertyMap getMap(final Global global, final boolean strict) {
-        return strict ? global.getStrictFunctionMap() : global.getFunctionMap();
+    private static PropertyMap getMap(final boolean strict) {
+        return strict ? strictmodemap$ : map$;
     }
 
     private static PropertyMap createBoundFunctionMap(final PropertyMap strictModeMap) {
@@ -192,14 +173,10 @@
     // Instance of this class is used as global anonymous function which
     // serves as Function.prototype object.
     private static class AnonymousFunction extends ScriptFunctionImpl {
-        private static final PropertyMap anonmap$ = PropertyMap.newMap().setIsShared();
-
-        static PropertyMap getInitialMap() {
-            return anonmap$;
-        }
+        private static final PropertyMap anonmap$ = PropertyMap.newMap();
 
         AnonymousFunction(final Global global) {
-            super("", GlobalFunctions.ANONYMOUS, global.getAnonymousFunctionMap(), null);
+            super("", GlobalFunctions.ANONYMOUS, anonmap$, null);
         }
     }
 
@@ -216,7 +193,7 @@
      * @return new ScriptFunction
      */
     static ScriptFunction makeFunction(final String name, final MethodHandle methodHandle, final MethodHandle[] specs) {
-        final ScriptFunctionImpl func = new ScriptFunctionImpl(name, methodHandle, null, specs, false, true, false);
+        final ScriptFunctionImpl func = new ScriptFunctionImpl(name, methodHandle, null, specs, ScriptFunctionData.IS_BUILTIN);
         func.setPrototype(UNDEFINED);
         // Non-constructor built-in functions do not have "prototype" property
         func.deleteOwnProperty(func.getMap().findProperty("prototype"));
@@ -280,13 +257,17 @@
     }
 
     @Override
-    public final void setPrototype(final Object prototype) {
-        this.prototype = prototype;
+    public final void setPrototype(final Object newProto) {
+        if (newProto instanceof ScriptObject && newProto != this.prototype && allocatorMap != null) {
+            // Replace our current allocator map with one that is associated with the new prototype.
+            allocatorMap = allocatorMap.changeProto((ScriptObject)newProto);
+        }
+        this.prototype = newProto;
     }
 
     // Internals below..
     private void init(final Global global) {
-        this.setProto(global.getFunctionPrototype());
+        this.setInitialProto(global.getFunctionPrototype());
         this.prototype = LAZY_PROTOTYPE;
 
         // We have to fill user accessor functions late as these are stored
--- a/src/jdk/nashorn/internal/parser/Parser.java	Thu Mar 20 16:26:54 2014 +0100
+++ b/src/jdk/nashorn/internal/parser/Parser.java	Fri Mar 21 17:52:03 2014 +0100
@@ -1896,6 +1896,7 @@
         case THIS:
             final String name = type.getName();
             next();
+            lc.setFlag(lc.getCurrentFunction(), FunctionNode.USES_THIS);
             return new IdentNode(primaryToken, finish, name);
         case IDENT:
             final IdentNode ident = getIdent();
--- a/src/jdk/nashorn/internal/runtime/AccessorProperty.java	Thu Mar 20 16:26:54 2014 +0100
+++ b/src/jdk/nashorn/internal/runtime/AccessorProperty.java	Fri Mar 21 17:52:03 2014 +0100
@@ -43,7 +43,6 @@
 import java.lang.invoke.MethodHandle;
 import java.lang.invoke.MethodHandles;
 import java.util.logging.Level;
-
 import jdk.nashorn.internal.codegen.ObjectClassGenerator;
 import jdk.nashorn.internal.codegen.types.Type;
 import jdk.nashorn.internal.lookup.Lookup;
@@ -150,24 +149,25 @@
     private Class<?> currentType;
 
     /**
-     * DELEGATE CONSTRUCTOR
+     * Delegate constructor for bound properties. This is used for properties created by
+     * {@link ScriptRuntime#mergeScope} and the Nashorn {@code Object.bindProperties} method.
+     * The former is used to add a script's defined globals to the current global scope while
+     * still storing them in a JO-prefixed ScriptObject class.
      *
-     * Delegate constructor. This is used when adding properties to the Global scope, which
-     * is necessary for outermost levels in a script (the ScriptObject is represented by
-     * a JO-prefixed ScriptObject class, but the properties need to be in the Global scope
-     * and are thus rebound with that as receiver
+     * <p>All properties created by this constructor have the {@link #IS_BOUND} flag set.</p>
      *
      * @param property  accessor property to rebind
      * @param delegate  delegate object to rebind receiver to
      */
     AccessorProperty(final AccessorProperty property, final Object delegate) {
-        super(property);
+        super(property, property.getFlags() | IS_BOUND);
 
         this.primitiveGetter = bindTo(property.primitiveGetter, delegate);
         this.primitiveSetter = bindTo(property.primitiveSetter, delegate);
         this.objectGetter    = bindTo(property.objectGetter, delegate);
         this.objectSetter    = bindTo(property.objectSetter, delegate);
 
+        // Properties created this way are bound to a delegate
         setCurrentType(property.getCurrentType());
     }
 
@@ -322,7 +322,7 @@
      * @param newType  new type
      */
     protected AccessorProperty(final AccessorProperty property, final Class<?> newType) {
-        super(property);
+        super(property, property.getFlags());
 
         this.GETTER_CACHE    = newType != property.getCurrentType() ? new MethodHandle[NOOF_TYPES] : property.GETTER_CACHE;
         this.primitiveGetter = property.primitiveGetter;
--- a/src/jdk/nashorn/internal/runtime/Context.java	Thu Mar 20 16:26:54 2014 +0100
+++ b/src/jdk/nashorn/internal/runtime/Context.java	Fri Mar 21 17:52:03 2014 +0100
@@ -33,6 +33,8 @@
 import java.io.File;
 import java.io.IOException;
 import java.io.PrintWriter;
+import java.lang.ref.ReferenceQueue;
+import java.lang.ref.SoftReference;
 import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Modifier;
 import java.net.MalformedURLException;
@@ -44,6 +46,7 @@
 import java.security.Permissions;
 import java.security.PrivilegedAction;
 import java.security.ProtectionDomain;
+import java.util.LinkedHashMap;
 import java.util.Map;
 import java.util.concurrent.atomic.AtomicLong;
 import jdk.internal.org.objectweb.asm.ClassReader;
@@ -154,16 +157,19 @@
     /** Is Context global debug mode enabled ? */
     public static final boolean DEBUG = Options.getBooleanProperty("nashorn.debug");
 
-    private static final ThreadLocal<ScriptObject> currentGlobal = new ThreadLocal<>();
+    private static final ThreadLocal<Global> currentGlobal = new ThreadLocal<>();
+
+    // class cache
+    private ClassCache classCache;
 
     /**
      * Get the current global scope
      * @return the current global scope
      */
-    public static ScriptObject getGlobal() {
+    public static Global getGlobal() {
         // This class in a package.access protected package.
         // Trusted code only can call this method.
-        return getGlobalTrusted();
+        return currentGlobal.get();
     }
 
     /**
@@ -172,10 +178,19 @@
      */
     public static void setGlobal(final ScriptObject global) {
         if (global != null && !(global instanceof Global)) {
-            throw new IllegalArgumentException("global is not an instance of Global!");
+            throw new IllegalArgumentException("not a global!");
         }
+        setGlobal((Global)global);
+    }
 
-        setGlobalTrusted(global);
+    /**
+     * Set the current global scope
+     * @param global the global scope
+     */
+    public static void setGlobal(final Global global) {
+        // This class in a package.access protected package.
+        // Trusted code only can call this method.
+        currentGlobal.set(global);
     }
 
     /**
@@ -196,8 +211,8 @@
      * @return error writer of the current context
      */
     public static PrintWriter getCurrentErr() {
-        final ScriptObject global = getGlobalTrusted();
-        return global != null ? global.getContext().getErr() : new PrintWriter(System.err);
+        final ScriptObject global = getGlobal();
+        return (global != null)? global.getContext().getErr() : new PrintWriter(System.err);
     }
 
     /**
@@ -349,6 +364,11 @@
             this.classPathLoader = null;
         }
 
+        final int cacheSize = env._class_cache_size;
+        if (cacheSize > 0) {
+            classCache = new ClassCache(cacheSize);
+        }
+
         // print version info if asked.
         if (env._version) {
             getErr().println("nashorn " + Version.version());
@@ -396,7 +416,7 @@
      * @return the property map of the current global scope
      */
     public static PropertyMap getGlobalMap() {
-        return Context.getGlobalTrusted().getMap();
+        return Context.getGlobal().getMap();
     }
 
     /**
@@ -426,7 +446,7 @@
         final String  file       = location == UNDEFINED || location == null ? "<eval>" : location.toString();
         final Source  source     = new Source(file, string);
         final boolean directEval = location != UNDEFINED; // is this direct 'eval' call or indirectly invoked eval?
-        final ScriptObject global = Context.getGlobalTrusted();
+        final Global  global = Context.getGlobal();
         ScriptObject scope = initialScope;
 
         // ECMA section 10.1.1 point 2 says eval code is strict if it begins
@@ -457,7 +477,7 @@
         // in the caller's environment. A new environment is created!
         if (strictFlag) {
             // Create a new scope object
-            final ScriptObject strictEvalScope = ((GlobalObject)global).newObject();
+            final ScriptObject strictEvalScope = global.newObject();
 
             // bless it as a "scope"
             strictEvalScope.setIsScope();
@@ -582,10 +602,10 @@
      * @throws IOException if source cannot be found or loaded
      */
     public Object loadWithNewGlobal(final Object from, final Object...args) throws IOException {
-        final ScriptObject oldGlobal = getGlobalTrusted();
-        final ScriptObject newGlobal = AccessController.doPrivileged(new PrivilegedAction<ScriptObject>() {
+        final Global oldGlobal = getGlobal();
+        final Global newGlobal = AccessController.doPrivileged(new PrivilegedAction<Global>() {
            @Override
-           public ScriptObject run() {
+           public Global run() {
                try {
                    return newGlobal();
                } catch (final RuntimeException e) {
@@ -598,17 +618,17 @@
         }, CREATE_GLOBAL_ACC_CTXT);
         // initialize newly created Global instance
         initGlobal(newGlobal);
-        setGlobalTrusted(newGlobal);
+        setGlobal(newGlobal);
 
         final Object[] wrapped = args == null? ScriptRuntime.EMPTY_ARRAY :  ScriptObjectMirror.wrapArray(args, oldGlobal);
-        newGlobal.put("arguments", ((GlobalObject)newGlobal).wrapAsObject(wrapped), env._strict);
+        newGlobal.put("arguments", newGlobal.wrapAsObject(wrapped), env._strict);
 
         try {
             // wrap objects from newGlobal's world as mirrors - but if result
             // is from oldGlobal's world, unwrap it!
             return ScriptObjectMirror.unwrap(ScriptObjectMirror.wrap(load(newGlobal, from), newGlobal), oldGlobal);
         } finally {
-            setGlobalTrusted(oldGlobal);
+            setGlobal(oldGlobal);
         }
     }
 
@@ -638,7 +658,7 @@
      * Checks that the given Class can be accessed from no permissions context.
      *
      * @param clazz Class object
-     * @throw SecurityException if not accessible
+     * @throws SecurityException if not accessible
      */
     public static void checkPackageAccess(final Class<?> clazz) {
         final SecurityManager sm = System.getSecurityManager();
@@ -655,12 +675,12 @@
      * Checks that the given package name can be accessed from no permissions context.
      *
      * @param pkgName package name
-     * @throw SecurityException if not accessible
+     * @throws SecurityException if not accessible
      */
     public static void checkPackageAccess(final String pkgName) {
         final SecurityManager sm = System.getSecurityManager();
         if (sm != null) {
-            checkPackageAccess(sm, pkgName.endsWith(".")? pkgName : pkgName + ".");
+            checkPackageAccess(sm, pkgName.endsWith(".") ? pkgName : pkgName + ".");
         }
     }
 
@@ -784,7 +804,7 @@
      *
      * @return the initialized global scope object.
      */
-    public ScriptObject createGlobal() {
+    public Global createGlobal() {
         return initGlobal(newGlobal());
     }
 
@@ -792,7 +812,7 @@
      * Create a new uninitialized global scope object
      * @return the global script object
      */
-    public ScriptObject newGlobal() {
+    public Global newGlobal() {
         return new Global(this);
     }
 
@@ -802,20 +822,16 @@
      * @param global the global
      * @return the initialized global scope object.
      */
-    public ScriptObject initGlobal(final ScriptObject global) {
-        if (!(global instanceof GlobalObject)) {
-            throw new IllegalArgumentException("not a global object!");
-        }
-
+    public Global initGlobal(final Global global) {
         // Need only minimal global object, if we are just compiling.
         if (!env._compile_only) {
-            final ScriptObject oldGlobal = Context.getGlobalTrusted();
+            final Global oldGlobal = Context.getGlobal();
             try {
-                Context.setGlobalTrusted(global);
+                Context.setGlobal(global);
                 // initialize global scope with builtin global objects
-                ((GlobalObject)global).initBuiltinObjects();
+                global.initBuiltinObjects();
             } finally {
-                Context.setGlobalTrusted(oldGlobal);
+                Context.setGlobal(oldGlobal);
             }
         }
 
@@ -823,30 +839,11 @@
     }
 
     /**
-     * Trusted variants - package-private
-     */
-
-    /**
-     * Return the current global scope
-     * @return current global scope
-     */
-    static ScriptObject getGlobalTrusted() {
-        return currentGlobal.get();
-    }
-
-    /**
-     * Set the current global scope
-     */
-    static void setGlobalTrusted(final ScriptObject global) {
-         currentGlobal.set(global);
-    }
-
-    /**
      * Return the current global's context
      * @return current global's context
      */
     static Context getContextTrusted() {
-        return Context.getGlobalTrusted().getContext();
+        return ((ScriptObject)Context.getGlobal()).getContext();
     }
 
     /**
@@ -911,16 +908,10 @@
         // start with no errors, no warnings.
         errMan.reset();
 
-        GlobalObject global = null;
-        Class<?> script;
-
-        if (env._class_cache_size > 0) {
-            global = (GlobalObject)Context.getGlobalTrusted();
-            script = global.findCachedClass(source);
-            if (script != null) {
-                Compiler.LOG.fine("Code cache hit for ", source, " avoiding recompile.");
-                return script;
-            }
+        Class<?> script = findCachedClass(source);
+        if (script != null) {
+            Compiler.LOG.fine("Code cache hit for ", source, " avoiding recompile.");
+            return script;
         }
 
         final FunctionNode functionNode = new Parser(env, source, errMan, strict).parse();
@@ -956,10 +947,7 @@
 
         final FunctionNode newFunctionNode = compiler.compile(CompilerConstants.DEFAULT_SCRIPT_NAME.symbolName(), functionNode);
         script = compiler.install(newFunctionNode);
-
-        if (global != null) {
-            global.cacheClass(source, script);
-        }
+        cacheClass(source, script);
 
         return script;
     }
@@ -981,4 +969,60 @@
     private long getUniqueScriptId() {
         return uniqueScriptId.getAndIncrement();
     }
+
+    /**
+     * Cache for compiled script classes.
+     */
+    @SuppressWarnings("serial")
+    private static class ClassCache extends LinkedHashMap<Source, ClassReference> {
+        private final int size;
+        private final ReferenceQueue<Class<?>> queue;
+
+        ClassCache(int size) {
+            super(size, 0.75f, true);
+            this.size = size;
+            this.queue = new ReferenceQueue<>();
+        }
+
+        void cache(final Source source, final Class<?> clazz) {
+            put(source, new ClassReference(clazz, queue, source));
+        }
+
+        @Override
+        protected boolean removeEldestEntry(final Map.Entry<Source, ClassReference> eldest) {
+            return size() > size;
+        }
+
+        @Override
+        public ClassReference get(Object key) {
+            for (ClassReference ref; (ref = (ClassReference)queue.poll()) != null; ) {
+                remove(ref.source);
+            }
+            return super.get(key);
+        }
+
+    }
+
+    private static class ClassReference extends SoftReference<Class<?>> {
+        private final Source source;
+
+        ClassReference(final Class<?> clazz, final ReferenceQueue<Class<?>> queue, final Source source) {
+            super(clazz, queue);
+            this.source = source;
+        }
+    }
+
+    // Class cache management
+    private Class<?> findCachedClass(final Source source) {
+        ClassReference ref = classCache == null ? null : classCache.get(source);
+        return ref != null ? ref.get() : null;
+    }
+
+    private void cacheClass(final Source source, final Class<?> clazz) {
+        if (classCache != null) {
+            classCache.cache(source, clazz);
+        }
+    }
+
+
 }
--- a/src/jdk/nashorn/internal/runtime/DebuggerSupport.java	Thu Mar 20 16:26:54 2014 +0100
+++ b/src/jdk/nashorn/internal/runtime/DebuggerSupport.java	Fri Mar 21 17:52:03 2014 +0100
@@ -77,7 +77,7 @@
      * @return context global.
      */
     static Object getGlobal() {
-        return Context.getGlobalTrusted();
+        return Context.getGlobal();
     }
 
     /**
@@ -89,7 +89,7 @@
      * @return Result of eval as string, or, an exception or null depending on returnException.
      */
     static Object eval(final ScriptObject scope, final Object self, final String string, final boolean returnException) {
-        final ScriptObject global = Context.getGlobalTrusted();
+        final ScriptObject global = Context.getGlobal();
         final ScriptObject initialScope = scope != null ? scope : global;
         final Object callThis = self != null ? self : global;
         final Context context = global.getContext();
--- a/src/jdk/nashorn/internal/runtime/ECMAErrors.java	Thu Mar 20 16:26:54 2014 +0100
+++ b/src/jdk/nashorn/internal/runtime/ECMAErrors.java	Fri Mar 21 17:52:03 2014 +0100
@@ -30,6 +30,7 @@
 import java.util.ResourceBundle;
 import jdk.nashorn.api.scripting.NashornException;
 import jdk.nashorn.internal.codegen.CompilerConstants;
+import jdk.nashorn.internal.objects.Global;
 import jdk.nashorn.internal.scripts.JS;
 
 /**
@@ -66,7 +67,7 @@
      * @return the resulting {@link ECMAException}
      */
     public static ECMAException asEcmaException(final ParserException e) {
-        return asEcmaException(Context.getGlobalTrusted(), e);
+        return asEcmaException(Context.getGlobal(), e);
     }
 
     /**
@@ -78,11 +79,11 @@
      *
      * @return the resulting {@link ECMAException}
      */
-    public static ECMAException asEcmaException(final ScriptObject global, final ParserException e) {
+    public static ECMAException asEcmaException(final Global global, final ParserException e) {
         final JSErrorType errorType = e.getErrorType();
         assert errorType != null : "error type for " + e + " was null";
 
-        final GlobalObject globalObj = (GlobalObject)global;
+        final Global globalObj    = global;
         final String       msg    = e.getMessage();
 
         // translate to ECMAScript Error object using error type
@@ -116,7 +117,7 @@
      * @return the resulting {@link ECMAException}
      */
     public static ECMAException syntaxError(final String msgId, final String... args) {
-        return syntaxError(Context.getGlobalTrusted(), msgId, args);
+        return syntaxError(Context.getGlobal(), msgId, args);
     }
 
     /**
@@ -128,7 +129,7 @@
      *
      * @return the resulting {@link ECMAException}
      */
-    public static ECMAException syntaxError(final ScriptObject global, final String msgId, final String... args) {
+    public static ECMAException syntaxError(final Global global, final String msgId, final String... args) {
         return syntaxError(global, null, msgId, args);
     }
 
@@ -142,7 +143,7 @@
      * @return the resulting {@link ECMAException}
      */
     public static ECMAException syntaxError(final Throwable cause, final String msgId, final String... args) {
-        return syntaxError(Context.getGlobalTrusted(), cause, msgId, args);
+        return syntaxError(Context.getGlobal(), cause, msgId, args);
     }
 
     /**
@@ -155,9 +156,9 @@
      *
      * @return the resulting {@link ECMAException}
      */
-    public static ECMAException syntaxError(final ScriptObject global, final Throwable cause, final String msgId, final String... args) {
+    public static ECMAException syntaxError(final Global global, final Throwable cause, final String msgId, final String... args) {
         final String msg = getMessage("syntax.error." + msgId, args);
-        return error(((GlobalObject)global).newSyntaxError(msg), cause);
+        return error(global.newSyntaxError(msg), cause);
     }
 
     /**
@@ -169,7 +170,7 @@
      * @return the resulting {@link ECMAException}
      */
     public static ECMAException typeError(final String msgId, final String... args) {
-        return typeError(Context.getGlobalTrusted(), msgId, args);
+        return typeError(Context.getGlobal(), msgId, args);
     }
 
     /**
@@ -181,7 +182,7 @@
      *
      * @return the resulting {@link ECMAException}
      */
-    public static ECMAException typeError(final ScriptObject global, final String msgId, final String... args) {
+    public static ECMAException typeError(final Global global, final String msgId, final String... args) {
         return typeError(global, null, msgId, args);
     }
 
@@ -195,7 +196,7 @@
      * @return the resulting {@link ECMAException}
      */
     public static ECMAException typeError(final Throwable cause, final String msgId, final String... args) {
-        return typeError(Context.getGlobalTrusted(), cause, msgId, args);
+        return typeError(Context.getGlobal(), cause, msgId, args);
     }
 
     /**
@@ -208,9 +209,9 @@
      *
      * @return the resulting {@link ECMAException}
      */
-    public static ECMAException typeError(final ScriptObject global, final Throwable cause, final String msgId, final String... args) {
+    public static ECMAException typeError(final Global global, final Throwable cause, final String msgId, final String... args) {
         final String msg = getMessage("type.error." + msgId, args);
-        return error(((GlobalObject)global).newTypeError(msg), cause);
+        return error(global.newTypeError(msg), cause);
     }
 
     /**
@@ -222,7 +223,7 @@
      * @return the resulting {@link ECMAException}
      */
     public static ECMAException rangeError(final String msgId, final String... args) {
-        return rangeError(Context.getGlobalTrusted(), msgId, args);
+        return rangeError(Context.getGlobal(), msgId, args);
     }
 
     /**
@@ -234,7 +235,7 @@
      *
      * @return the resulting {@link ECMAException}
      */
-    public static ECMAException rangeError(final ScriptObject global, final String msgId, final String... args) {
+    public static ECMAException rangeError(final Global global, final String msgId, final String... args) {
         return rangeError(global, null, msgId, args);
     }
 
@@ -248,7 +249,7 @@
      * @return the resulting {@link ECMAException}
      */
     public static ECMAException rangeError(final Throwable cause, final String msgId, final String... args) {
-        return rangeError(Context.getGlobalTrusted(), cause, msgId, args);
+        return rangeError(Context.getGlobal(), cause, msgId, args);
     }
 
     /**
@@ -261,9 +262,9 @@
      *
      * @return the resulting {@link ECMAException}
      */
-    public static ECMAException rangeError(final ScriptObject global, final Throwable cause, final String msgId, final String... args) {
+    public static ECMAException rangeError(final Global global, final Throwable cause, final String msgId, final String... args) {
         final String msg = getMessage("range.error." + msgId, args);
-        return error(((GlobalObject)global).newRangeError(msg), cause);
+        return error(global.newRangeError(msg), cause);
     }
 
     /**
@@ -275,7 +276,7 @@
      * @return the resulting {@link ECMAException}
      */
     public static ECMAException referenceError(final String msgId, final String... args) {
-        return referenceError(Context.getGlobalTrusted(), msgId, args);
+        return referenceError(Context.getGlobal(), msgId, args);
     }
 
     /**
@@ -287,7 +288,7 @@
      *
      * @return the resulting {@link ECMAException}
      */
-    public static ECMAException referenceError(final ScriptObject global, final String msgId, final String... args) {
+    public static ECMAException referenceError(final Global global, final String msgId, final String... args) {
         return referenceError(global, null, msgId, args);
     }
 
@@ -301,7 +302,7 @@
      * @return the resulting {@link ECMAException}
      */
     public static ECMAException referenceError(final Throwable cause, final String msgId, final String... args) {
-        return referenceError(Context.getGlobalTrusted(), cause, msgId, args);
+        return referenceError(Context.getGlobal(), cause, msgId, args);
     }
 
     /**
@@ -314,9 +315,9 @@
      *
      * @return the resulting {@link ECMAException}
      */
-    public static ECMAException referenceError(final ScriptObject global, final Throwable cause, final String msgId, final String... args) {
+    public static ECMAException referenceError(final Global global, final Throwable cause, final String msgId, final String... args) {
         final String msg = getMessage("reference.error." + msgId, args);
-        return error(((GlobalObject)global).newReferenceError(msg), cause);
+        return error(global.newReferenceError(msg), cause);
     }
 
     /**
@@ -328,7 +329,7 @@
      * @return the resulting {@link ECMAException}
      */
     public static ECMAException uriError(final String msgId, final String... args) {
-        return uriError(Context.getGlobalTrusted(), msgId, args);
+        return uriError(Context.getGlobal(), msgId, args);
     }
 
     /**
@@ -340,7 +341,7 @@
      *
      * @return the resulting {@link ECMAException}
      */
-    public static ECMAException uriError(final ScriptObject global, final String msgId, final String... args) {
+    public static ECMAException uriError(final Global global, final String msgId, final String... args) {
         return uriError(global, null, msgId, args);
     }
 
@@ -354,7 +355,7 @@
      * @return the resulting {@link ECMAException}
      */
     public static ECMAException uriError(final Throwable cause, final String msgId, final String... args) {
-        return uriError(Context.getGlobalTrusted(), cause, msgId, args);
+        return uriError(Context.getGlobal(), cause, msgId, args);
     }
 
     /**
@@ -367,9 +368,9 @@
      *
      * @return the resulting {@link ECMAException}
      */
-    public static ECMAException uriError(final ScriptObject global, final Throwable cause, final String msgId, final String... args) {
+    public static ECMAException uriError(final Global global, final Throwable cause, final String msgId, final String... args) {
         final String msg = getMessage("uri.error." + msgId, args);
-        return error(((GlobalObject)global).newURIError(msg), cause);
+        return error(global.newURIError(msg), cause);
     }
 
     /**
--- a/src/jdk/nashorn/internal/runtime/FinalScriptFunctionData.java	Thu Mar 20 16:26:54 2014 +0100
+++ b/src/jdk/nashorn/internal/runtime/FinalScriptFunctionData.java	Fri Mar 21 17:52:03 2014 +0100
@@ -37,32 +37,28 @@
     /**
      * Constructor - used for bind
      *
-     * @param name          name
-     * @param arity         arity
-     * @param functions     precompiled code
-     * @param isStrict      strict
-     * @param isBuiltin     builtin
-     * @param isConstructor constructor
+     * @param name      name
+     * @param arity     arity
+     * @param functions precompiled code
+     * @param flags     {@link ScriptFunctionData} flags
      */
-    FinalScriptFunctionData(final String name, int arity, CompiledFunctions functions, final boolean isStrict, final boolean isBuiltin, final boolean isConstructor, final boolean isVariableArity) {
-        super(name, arity, isStrict, isBuiltin, isConstructor, isVariableArity);
+    FinalScriptFunctionData(final String name, final int arity, final CompiledFunctions functions, final int flags) {
+        super(name, arity, flags);
         assert !functions.needsCallee();
         code.addAll(functions);
     }
 
     /**
-     * Constructor - used from ScriptFunction. This assumes that we have code alraedy for the
+     * Constructor - used from ScriptFunction. This assumes that we have code already for the
      * method (typically a native method) and possibly specializations.
      *
-     * @param name           name
-     * @param mh             method handle for generic version of method
-     * @param specs          specializations
-     * @param isStrict       strict
-     * @param isBuiltin      builtin
-     * @param isConstructor  constructor
+     * @param name  name
+     * @param mh    method handle for generic version of method
+     * @param specs specializations
+     * @param flags {@link ScriptFunctionData} flags
      */
-    FinalScriptFunctionData(final String name, final MethodHandle mh, final MethodHandle[] specs, final boolean isStrict, final boolean isBuiltin, final boolean isConstructor) {
-        super(name, methodHandleArity(mh), isStrict, isBuiltin, isConstructor, isVarArg(mh));
+    FinalScriptFunctionData(final String name, final MethodHandle mh, final MethodHandle[] specs, final int flags) {
+        super(name, methodHandleArity(mh), flags);
 
         addInvoker(mh);
         if (specs != null) {
--- a/src/jdk/nashorn/internal/runtime/GlobalObject.java	Thu Mar 20 16:26:54 2014 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,244 +0,0 @@
-/*
- * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.  Oracle designates this
- * particular file as subject to the "Classpath" exception as provided
- * by Oracle in the LICENSE file that accompanied this code.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-
-package jdk.nashorn.internal.runtime;
-
-import java.lang.invoke.MethodHandle;
-import java.util.concurrent.Callable;
-import jdk.internal.dynalink.linker.GuardedInvocation;
-import jdk.internal.dynalink.linker.LinkRequest;
-import jdk.nashorn.internal.runtime.linker.InvokeByName;
-
-/**
- * Runtime interface to the global scope objects.
- */
-
-public interface GlobalObject {
-    /**
-     * Is this global of the given Context?
-     * @param ctxt the context
-     * @return true if this global belongs to the given Context
-     */
-    public boolean isOfContext(final Context ctxt);
-
-    /**
-     * Does this global belong to a strict Context?
-     * @return true if this global belongs to a strict Context
-     */
-    public boolean isStrictContext();
-
-    /**
-     * Initialize standard builtin objects like "Object", "Array", "Function" etc.
-     * as well as our extension builtin objects like "Java", "JSAdapter" as properties
-     * of the global scope object.
-     */
-    public void initBuiltinObjects();
-
-    /**
-     * Wrapper for {@link jdk.nashorn.internal.objects.Global#newScriptFunction(String, MethodHandle, ScriptObject, boolean)}
-     *
-     * @param name   function name
-     * @param handle invocation handle for function
-     * @param scope  the scope
-     * @param strict are we in strict mode
-     *
-     * @return new script function
-     */
-   public ScriptFunction newScriptFunction(String name, MethodHandle handle, ScriptObject scope, boolean strict);
-
-    /**
-     * Wrapper for {@link jdk.nashorn.internal.objects.Global#wrapAsObject(Object)}
-     *
-     * @param obj object to wrap
-     * @return    wrapped object
-     */
-   public Object wrapAsObject(Object obj);
-
-
-    /**
-     * Wrapper for {@link jdk.nashorn.internal.objects.Global#primitiveLookup(LinkRequest, Object)}
-     *
-     * @param request the link request for the dynamic call site.
-     * @param self     self reference
-     *
-     * @return guarded invocation
-     */
-   public GuardedInvocation primitiveLookup(LinkRequest request, Object self);
-
-
-    /**
-     * Wrapper for {@link jdk.nashorn.internal.objects.Global#newObject()}
-     *
-     * @return the new ScriptObject
-     */
-   public ScriptObject newObject();
-
-    /**
-     * Wrapper for {@link jdk.nashorn.internal.objects.Global#isError(ScriptObject)}
-     *
-     * @param sobj to check if it is an error object
-     * @return true if error object
-     */
-   public boolean isError(ScriptObject sobj);
-
-    /**
-     * Wrapper for {@link jdk.nashorn.internal.objects.Global#newError(String)}
-     *
-     * @param msg the error message
-     *
-     * @return the new ScriptObject representing the error
-     */
-   public ScriptObject newError(String msg);
-
-    /**
-     * Wrapper for {@link jdk.nashorn.internal.objects.Global#newEvalError(String)}
-     *
-     * @param msg the error message
-     *
-     * @return the new ScriptObject representing the eval error
-     */
-   public ScriptObject newEvalError(String msg);
-
-    /**
-     * Wrapper for {@link jdk.nashorn.internal.objects.Global#newRangeError(String)}
-     *
-     * @param msg the error message
-     *
-     * @return the new ScriptObject representing the range error
-     */
-   public ScriptObject newRangeError(String msg);
-
-    /**
-     * Wrapper for {@link jdk.nashorn.internal.objects.Global#newReferenceError(String)}
-     *
-     * @param msg the error message
-     *
-     * @return the new ScriptObject representing the reference error
-     */
-   public ScriptObject newReferenceError(String msg);
-
-    /**
-     * Wrapper for {@link jdk.nashorn.internal.objects.Global#newSyntaxError(String)}
-     *
-     * @param msg the error message
-     *
-     * @return the new ScriptObject representing the syntax error
-     */
-   public ScriptObject newSyntaxError(String msg);
-
-    /**
-     * Wrapper for {@link jdk.nashorn.internal.objects.Global#newTypeError(String)}
-     *
-     * @param msg the error message
-     *
-     * @return the new ScriptObject representing the type error
-     */
-   public ScriptObject newTypeError(String msg);
-
-    /**
-     * Wrapper for {@link jdk.nashorn.internal.objects.Global#newURIError(String)}
-     *
-     * @param msg the error message
-     *
-     * @return the new ScriptObject representing the URI error
-     */
-    public ScriptObject newURIError(String msg);
-
-    /**
-     * Wrapper for {@link jdk.nashorn.internal.objects.Global#newGenericDescriptor(boolean, boolean)}
-     *
-     * @param configurable is the described property configurable
-     * @param enumerable   is the described property enumerable
-     *
-     * @return property descriptor
-     */
-    public PropertyDescriptor newGenericDescriptor(boolean configurable, boolean enumerable);
-
-    /**
-     * Wrapper for {@link jdk.nashorn.internal.objects.Global#newDataDescriptor(Object, boolean, boolean, boolean)}
-     *
-     * @param value        data value
-     * @param configurable is the described property configurable
-     * @param enumerable   is the described property enumerable
-     * @param writable     is the described property writable
-     *
-     * @return property descriptor
-     */
-    public PropertyDescriptor newDataDescriptor(Object value, boolean configurable, boolean enumerable, boolean writable);
-
-    /**
-     * Wrapper for {@link jdk.nashorn.internal.objects.Global#newAccessorDescriptor(Object, Object, boolean, boolean)}
-     *
-     * @param get          property getter, or null if none
-     * @param set          property setter, or null if none
-     * @param configurable is the described property configurable
-     * @param enumerable   is the described property enumerable
-     *
-     * @return property descriptor
-     */
-    public PropertyDescriptor newAccessorDescriptor(Object get, Object set, boolean configurable, boolean enumerable);
-
-    /**
-     * Wrapper for {@link jdk.nashorn.internal.objects.Global#getDefaultValue(ScriptObject, Class)}
-     *
-     * @param sobj     script object
-     * @param typeHint type hint
-     *
-     * @return default value
-     */
-    public Object getDefaultValue(ScriptObject sobj, Class<?> typeHint);
-
-    /**
-     * Find the compiled Class for the given script source, if available
-     *
-     * @param source Source object of the script
-     * @return compiled Class object or null
-     */
-    public Class<?> findCachedClass(Source source);
-
-    /**
-     * Put the Source associated Class object in the Source-to-Class cache
-     *
-     * @param source Source of the script
-     * @param clazz compiled Class object for the source
-     */
-    public void cacheClass(Source source, Class<?> clazz);
-
-    /**
-     * Get cached InvokeByName object for the given key
-     * @param key key to be associated with InvokeByName object
-     * @param creator if InvokeByName is absent 'creator' is called to make one (lazy init)
-     * @return InvokeByName object associated with the key.
-     */
-    public InvokeByName getInvokeByName(final Object key, final Callable<InvokeByName> creator);
-
-    /**
-     * Get cached dynamic method handle for the given key
-     * @param key key to be associated with dynamic method handle
-     * @param creator if method handle is absent 'creator' is called to make one (lazy init)
-     * @return dynamic method handle associated with the key.
-     */
-    public MethodHandle getDynamicInvoker(final Object key, final Callable<MethodHandle> creator);
-}
--- a/src/jdk/nashorn/internal/runtime/JSONFunctions.java	Thu Mar 20 16:26:54 2014 +0100
+++ b/src/jdk/nashorn/internal/runtime/JSONFunctions.java	Fri Mar 21 17:52:03 2014 +0100
@@ -33,6 +33,7 @@
 import jdk.nashorn.internal.ir.ObjectNode;
 import jdk.nashorn.internal.ir.PropertyNode;
 import jdk.nashorn.internal.ir.UnaryNode;
+import jdk.nashorn.internal.objects.Global;
 import jdk.nashorn.internal.parser.JSONParser;
 import jdk.nashorn.internal.parser.TokenType;
 import jdk.nashorn.internal.runtime.arrays.ArrayIndex;
@@ -47,7 +48,7 @@
     private static final Object REVIVER_INVOKER = new Object();
 
     private static MethodHandle getREVIVER_INVOKER() {
-        return ((GlobalObject)Context.getGlobal()).getDynamicInvoker(REVIVER_INVOKER,
+        return Context.getGlobal().getDynamicInvoker(REVIVER_INVOKER,
                 new Callable<MethodHandle>() {
                     @Override
                     public MethodHandle call() {
@@ -88,7 +89,7 @@
             throw ECMAErrors.syntaxError(e, "invalid.json", e.getMessage());
         }
 
-        final ScriptObject global = Context.getGlobalTrusted();
+        final Global global = Context.getGlobal();
         Object unfiltered = convertNode(global, node);
         return applyReviver(global, unfiltered, reviver);
     }
@@ -98,10 +99,10 @@
     // parse helpers
 
     // apply 'reviver' function if available
-    private static Object applyReviver(final ScriptObject global, final Object unfiltered, final Object reviver) {
+    private static Object applyReviver(final Global global, final Object unfiltered, final Object reviver) {
         if (reviver instanceof ScriptFunction) {
-            assert global instanceof GlobalObject;
-            final ScriptObject root = ((GlobalObject)global).newObject();
+            assert global instanceof Global;
+            final ScriptObject root = global.newObject();
             root.addOwnProperty("", Property.WRITABLE_ENUMERABLE_CONFIGURABLE, unfiltered);
             return walk(root, "", (ScriptFunction)reviver);
         }
@@ -138,8 +139,8 @@
     }
 
     // Converts IR node to runtime value
-    private static Object convertNode(final ScriptObject global, final Node node) {
-        assert global instanceof GlobalObject;
+    private static Object convertNode(final Global global, final Node node) {
+        assert global instanceof Global;
 
         if (node instanceof LiteralNode) {
             // check for array literal
@@ -157,7 +158,7 @@
                     for (final Node elem : elements) {
                         values[index++] = JSType.toNumber(convertNode(global, elem));
                     }
-                    return ((GlobalObject)global).wrapAsObject(values);
+                    return global.wrapAsObject(values);
                 }
 
                 final Object[] values = new Object[elements.length];
@@ -167,14 +168,14 @@
                     values[index++] = convertNode(global, elem);
                 }
 
-                return ((GlobalObject)global).wrapAsObject(values);
+                return global.wrapAsObject(values);
             }
 
             return ((LiteralNode<?>)node).getValue();
 
         } else if (node instanceof ObjectNode) {
             final ObjectNode   objNode  = (ObjectNode) node;
-            final ScriptObject object   = ((GlobalObject)global).newObject();
+            final ScriptObject object   = global.newObject();
 
             for (final PropertyNode pNode: objNode.getElements()) {
                 final Node         valueNode = pNode.getValue();
--- a/src/jdk/nashorn/internal/runtime/JSType.java	Thu Mar 20 16:26:54 2014 +0100
+++ b/src/jdk/nashorn/internal/runtime/JSType.java	Fri Mar 21 17:52:03 2014 +0100
@@ -36,11 +36,11 @@
 import java.util.Collections;
 import java.util.Deque;
 import java.util.List;
-
 import jdk.internal.dynalink.beans.StaticClass;
 import jdk.nashorn.api.scripting.JSObject;
 import jdk.nashorn.internal.codegen.CompilerConstants.Call;
 import jdk.nashorn.internal.codegen.types.Type;
+import jdk.nashorn.internal.objects.Global;
 import jdk.nashorn.internal.parser.Lexer;
 import jdk.nashorn.internal.runtime.arrays.ArrayLikeIterator;
 import jdk.nashorn.internal.runtime.linker.Bootstrap;
@@ -1100,7 +1100,7 @@
      * @return the wrapped object
      */
     public static Object toScriptObject(final Object obj) {
-        return toScriptObject(Context.getGlobalTrusted(), obj);
+        return toScriptObject(Context.getGlobal(), obj);
     }
 
     /**
@@ -1113,7 +1113,7 @@
      *
      * @return the wrapped object
      */
-    public static Object toScriptObject(final ScriptObject global, final Object obj) {
+    public static Object toScriptObject(final Global global, final Object obj) {
         if (nullOrUndefined(obj)) {
             throw typeError(global, "not.an.object", ScriptRuntime.safeToString(obj));
         }
@@ -1122,7 +1122,7 @@
             return obj;
         }
 
-        return ((GlobalObject)global).wrapAsObject(obj);
+        return global.wrapAsObject(obj);
     }
 
     /**
@@ -1232,7 +1232,7 @@
         if (obj instanceof ScriptObject) {
             if (safe) {
                 final ScriptObject sobj = (ScriptObject)obj;
-                final GlobalObject gobj = (GlobalObject)Context.getGlobalTrusted();
+                final Global gobj = Context.getGlobal();
                 return gobj.isError(sobj) ?
                     ECMAException.safeToString(sobj) :
                     sobj.safeToString();
--- a/src/jdk/nashorn/internal/runtime/ListAdapter.java	Thu Mar 20 16:26:54 2014 +0100
+++ b/src/jdk/nashorn/internal/runtime/ListAdapter.java	Fri Mar 21 17:52:03 2014 +0100
@@ -34,6 +34,7 @@
 import java.util.concurrent.Callable;
 import jdk.nashorn.api.scripting.JSObject;
 import jdk.nashorn.api.scripting.ScriptObjectMirror;
+import jdk.nashorn.internal.objects.Global;
 import jdk.nashorn.internal.runtime.linker.Bootstrap;
 import jdk.nashorn.internal.runtime.linker.InvokeByName;
 
@@ -54,7 +55,7 @@
     // These add to the back and front of the list
     private static final Object PUSH    = new Object();
     private static InvokeByName getPUSH() {
-        return ((GlobalObject)Context.getGlobal()).getInvokeByName(PUSH,
+        return Context.getGlobal().getInvokeByName(PUSH,
                 new Callable<InvokeByName>() {
                     @Override
                     public InvokeByName call() {
@@ -65,7 +66,7 @@
 
     private static final Object UNSHIFT = new Object();
     private static InvokeByName getUNSHIFT() {
-        return ((GlobalObject)Context.getGlobal()).getInvokeByName(UNSHIFT,
+        return Context.getGlobal().getInvokeByName(UNSHIFT,
                 new Callable<InvokeByName>() {
                     @Override
                     public InvokeByName call() {
@@ -77,7 +78,7 @@
     // These remove from the back and front of the list
     private static final Object POP = new Object();
     private static InvokeByName getPOP() {
-        return ((GlobalObject)Context.getGlobal()).getInvokeByName(POP,
+        return Context.getGlobal().getInvokeByName(POP,
                 new Callable<InvokeByName>() {
                     @Override
                     public InvokeByName call() {
@@ -88,7 +89,7 @@
 
     private static final Object SHIFT = new Object();
     private static InvokeByName getSHIFT() {
-        return ((GlobalObject)Context.getGlobal()).getInvokeByName(SHIFT,
+        return Context.getGlobal().getInvokeByName(SHIFT,
                 new Callable<InvokeByName>() {
                     @Override
                     public InvokeByName call() {
@@ -100,7 +101,7 @@
     // These insert and remove in the middle of the list
     private static final Object SPLICE_ADD = new Object();
     private static InvokeByName getSPLICE_ADD() {
-        return ((GlobalObject)Context.getGlobal()).getInvokeByName(SPLICE_ADD,
+        return Context.getGlobal().getInvokeByName(SPLICE_ADD,
                 new Callable<InvokeByName>() {
                     @Override
                     public InvokeByName call() {
@@ -111,7 +112,7 @@
 
     private static final Object SPLICE_REMOVE = new Object();
     private static InvokeByName getSPLICE_REMOVE() {
-        return ((GlobalObject)Context.getGlobal()).getInvokeByName(SPLICE_REMOVE,
+        return  Context.getGlobal().getInvokeByName(SPLICE_REMOVE,
                 new Callable<InvokeByName>() {
                     @Override
                     public InvokeByName call() {
--- a/src/jdk/nashorn/internal/runtime/NativeJavaPackage.java	Thu Mar 20 16:26:54 2014 +0100
+++ b/src/jdk/nashorn/internal/runtime/NativeJavaPackage.java	Fri Mar 21 17:52:03 2014 +0100
@@ -37,7 +37,6 @@
 import jdk.internal.dynalink.support.Guards;
 import jdk.nashorn.internal.lookup.MethodHandleFactory;
 import jdk.nashorn.internal.lookup.MethodHandleFunctionality;
-import jdk.nashorn.internal.objects.NativeJava;
 import jdk.nashorn.internal.objects.annotations.Attribute;
 import jdk.nashorn.internal.objects.annotations.Function;
 
@@ -54,7 +53,7 @@
  * var ArrayList = java.util.ArrayList
  * var list = new ArrayList
  * </pre>
- * You can also use {@link NativeJava#type(Object, Object)} to access Java classes. These two statements are mostly
+ * You can also use {@link jdk.nashorn.internal.objects.NativeJava#type(Object, Object)} to access Java classes. These two statements are mostly
  * equivalent:
  * <pre>
  * var listType1 = java.util.ArrayList
--- a/src/jdk/nashorn/internal/runtime/ParserException.java	Thu Mar 20 16:26:54 2014 +0100
+++ b/src/jdk/nashorn/internal/runtime/ParserException.java	Fri Mar 21 17:52:03 2014 +0100
@@ -26,6 +26,7 @@
 package jdk.nashorn.internal.runtime;
 
 import jdk.nashorn.api.scripting.NashornException;
+import jdk.nashorn.internal.objects.Global;
 import jdk.nashorn.internal.parser.Token;
 
 /**
@@ -110,7 +111,7 @@
      * Throw this {@code ParserException} as one of the 7 native JavaScript errors
      * @param global global scope object
      */
-    public void throwAsEcmaException(final ScriptObject global) {
+    public void throwAsEcmaException(final Global global) {
         throw ECMAErrors.asEcmaException(global, this);
     }
 }
--- a/src/jdk/nashorn/internal/runtime/Property.java	Thu Mar 20 16:26:54 2014 +0100
+++ b/src/jdk/nashorn/internal/runtime/Property.java	Fri Mar 21 17:52:03 2014 +0100
@@ -85,6 +85,10 @@
      */
     public static final int IS_NASGEN_PRIMITIVE = 1 << 7;
 
+    /** Is this property bound to a receiver? This means get/set operations will be delegated to
+     *  a statically defined object instead of the object passed as callsite parameter. */
+    public static final int IS_BOUND = 1 << 8;
+
     /** Property key. */
     private final String key;
 
@@ -113,10 +117,10 @@
      *
      * @param property source property
      */
-    Property(final Property property) {
+    Property(final Property property, final int flags) {
         this.key   = property.key;
-        this.flags = property.flags;
         this.slot  = property.slot;
+        this.flags = flags;
     }
 
     /**
@@ -258,6 +262,16 @@
     }
 
     /**
+     * Is this property bound to a receiver? If this method returns {@code true} get and set operations
+     * will be delegated to a statically bound object instead of the object passed as parameter.
+     *
+     * @return true if this is a bound property
+     */
+    public boolean isBound() {
+        return (flags & IS_BOUND) == IS_BOUND;
+    }
+
+    /**
      * Does this property use any slots in the spill array described in
      * {@link Property#isSpill}? In that case how many. Currently a property
      * only uses max one spill slot, but this may change in future representations
--- a/src/jdk/nashorn/internal/runtime/PropertyListener.java	Thu Mar 20 16:26:54 2014 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,66 +0,0 @@
-/*
- * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.  Oracle designates this
- * particular file as subject to the "Classpath" exception as provided
- * by Oracle in the LICENSE file that accompanied this code.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-
-package jdk.nashorn.internal.runtime;
-
-/**
- * Property change listener gets notified whenever properties are added/deleted/modified.
- */
-public interface PropertyListener {
-    /**
-     * A new property is being added.
-     *
-     * @param object The ScriptObject to which property was added.
-     * @param prop The new Property added.
-     */
-    public void propertyAdded(ScriptObject object, Property prop);
-
-    /**
-     * An existing property is being deleted.
-     *
-     * @param object The ScriptObject whose property is being deleted.
-     * @param prop The property being deleted.
-     */
-    public void propertyDeleted(ScriptObject object, Property prop);
-
-    /**
-     * An existing Property is being replaced with a new Property.
-     *
-     * @param object The ScriptObject whose property is being modified.
-     * @param oldProp The old property that is being replaced.
-     * @param newProp The new property that replaces the old property.
-     *
-     */
-    public void propertyModified(ScriptObject object, Property oldProp, Property newProp);
-
-    /**
-     * Given object's __proto__ has changed.
-     *
-     * @param object object whose __proto__ has changed.
-     * @param oldProto old __proto__
-     * @param newProto new __proto__
-     */
-    public void protoChanged(ScriptObject object, ScriptObject oldProto, ScriptObject newProto);
-}
--- a/src/jdk/nashorn/internal/runtime/PropertyListenerManager.java	Thu Mar 20 16:26:54 2014 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,179 +0,0 @@
-/*
- * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.  Oracle designates this
- * particular file as subject to the "Classpath" exception as provided
- * by Oracle in the LICENSE file that accompanied this code.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-
-package jdk.nashorn.internal.runtime;
-
-import java.util.Map;
-import java.util.WeakHashMap;
-
-/**
- * Helper class to manage property listeners and notification.
- */
-public class PropertyListenerManager implements PropertyListener {
-    PropertyListenerManager() {}
-
-    /** property listeners for this object. */
-    private Map<PropertyListener,Boolean> listeners;
-
-    // These counters are updated in debug mode
-    private static int listenersAdded;
-    private static int listenersRemoved;
-
-    /**
-     * Return aggregate listeners added to all PropertyListenerManagers
-     * @return the listenersAdded
-     */
-    public static int getListenersAdded() {
-        return listenersAdded;
-    }
-
-    /**
-     * Return aggregate listeners removed from all PropertyListenerManagers
-     * @return the listenersRemoved
-     */
-    public static int getListenersRemoved() {
-        return listenersRemoved;
-    }
-
-    /**
-     * Return listeners added to this PropertyListenerManager.
-     * @return the listener count
-     */
-    public final int getListenerCount() {
-        return listeners != null? listeners.size() : 0;
-    }
-
-    // Property listener management methods
-
-    /**
-     * Add a property listener to this object.
-     *
-     * @param listener The property listener that is added.
-     */
-    public synchronized final void addPropertyListener(final PropertyListener listener) {
-        if (listeners == null) {
-            listeners = new WeakHashMap<>();
-        }
-
-        if (Context.DEBUG) {
-            listenersAdded++;
-        }
-        listeners.put(listener, Boolean.TRUE);
-    }
-
-    /**
-     * Remove a property listener from this object.
-     *
-     * @param listener The property listener that is removed.
-     */
-    public synchronized final void removePropertyListener(final PropertyListener listener) {
-        if (listeners != null) {
-            if (Context.DEBUG) {
-                listenersRemoved++;
-            }
-            listeners.remove(listener);
-        }
-    }
-
-    /**
-     * This method can be called to notify property addition to this object's listeners.
-     *
-     * @param object The ScriptObject to which property was added.
-     * @param prop The property being added.
-     */
-    protected synchronized final void notifyPropertyAdded(final ScriptObject object, final Property prop) {
-        if (listeners != null) {
-            for (final PropertyListener listener : listeners.keySet()) {
-                listener.propertyAdded(object, prop);
-            }
-        }
-    }
-
-    /**
-     * This method can be called to notify property deletion to this object's listeners.
-     *
-     * @param object The ScriptObject from which property was deleted.
-     * @param prop The property being deleted.
-     */
-    protected synchronized final void notifyPropertyDeleted(final ScriptObject object, final Property prop) {
-        if (listeners != null) {
-            for (final PropertyListener listener : listeners.keySet()) {
-                listener.propertyDeleted(object, prop);
-            }
-        }
-    }
-
-    /**
-     * This method can be called to notify property modification to this object's listeners.
-     *
-     * @param object The ScriptObject to which property was modified.
-     * @param oldProp The old property being replaced.
-     * @param newProp The new property that replaces the old property.
-     */
-    protected synchronized final void notifyPropertyModified(final ScriptObject object, final Property oldProp, final Property newProp) {
-        if (listeners != null) {
-            for (final PropertyListener listener : listeners.keySet()) {
-                listener.propertyModified(object, oldProp, newProp);
-            }
-        }
-    }
-
-    /**
-     * This method can be called to notify __proto__ modification to this object's listeners.
-     *
-     * @param object The ScriptObject whose __proto__ was changed.
-     * @param oldProto old __proto__
-     * @param newProto new __proto__
-     */
-    protected synchronized final void notifyProtoChanged(final ScriptObject object, final ScriptObject oldProto, final ScriptObject newProto) {
-        if (listeners != null) {
-            for (final PropertyListener listener : listeners.keySet()) {
-                listener.protoChanged(object, oldProto, newProto);
-            }
-        }
-    }
-
-    // PropertyListener methods
-
-    @Override
-    public final void propertyAdded(final ScriptObject object, final Property prop) {
-        notifyPropertyAdded(object, prop);
-    }
-
-    @Override
-    public final void propertyDeleted(final ScriptObject object, final Property prop) {
-        notifyPropertyDeleted(object, prop);
-    }
-
-    @Override
-    public final void propertyModified(final ScriptObject object, final Property oldProp, final Property newProp) {
-        notifyPropertyModified(object, oldProp, newProp);
-    }
-
-    @Override
-    public final void protoChanged(final ScriptObject object, final ScriptObject oldProto, final ScriptObject newProto) {
-        notifyProtoChanged(object, oldProto, newProto);
-    }
-}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/jdk/nashorn/internal/runtime/PropertyListeners.java	Fri Mar 21 17:52:03 2014 +0100
@@ -0,0 +1,222 @@
+/*
+ * Copyright (c) 2010, 2014, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package jdk.nashorn.internal.runtime;
+
+import java.util.Map;
+import java.util.Set;
+import java.util.WeakHashMap;
+
+/**
+ * Helper class to manage property listeners and notification.
+ */
+public class PropertyListeners {
+
+    private Map<String, WeakPropertyMapSet> listeners;
+
+    // These counters are updated in debug mode
+    private static int listenersAdded;
+    private static int listenersRemoved;
+
+    /**
+     * Copy constructor
+     * @param listener listener to copy
+     */
+    PropertyListeners(final PropertyListeners listener) {
+        if (listener != null && listener.listeners != null) {
+            this.listeners = new WeakHashMap<>(listener.listeners);
+        }
+    }
+
+    /**
+     * Return aggregate listeners added to all PropertyListenerManagers
+     * @return the listenersAdded
+     */
+    public static int getListenersAdded() {
+        return listenersAdded;
+    }
+
+    /**
+     * Return aggregate listeners removed from all PropertyListenerManagers
+     * @return the listenersRemoved
+     */
+    public static int getListenersRemoved() {
+        return listenersRemoved;
+    }
+
+    /**
+     * Return listeners added to this ScriptObject.
+     * @param obj the object
+     * @return the listener count
+     */
+    public static int getListenerCount(final ScriptObject obj) {
+        final PropertyListeners propertyListeners = obj.getMap().getListeners();
+        if (propertyListeners != null) {
+            return propertyListeners.listeners == null ? 0 : propertyListeners.listeners.size();
+        }
+        return 0;
+    }
+
+    // Property listener management methods
+
+    /**
+     * Add {@code propertyMap} as property listener to {@code listeners} using key {@code key} by
+     * creating and returning a new {@code PropertyListeners} instance.
+     *
+     * @param listeners the original property listeners instance, may be null
+     * @param key the property key
+     * @param propertyMap the property map
+     * @return the new property map
+     */
+    public static PropertyListeners addListener(final PropertyListeners listeners, final String key, final PropertyMap propertyMap) {
+        final PropertyListeners newListeners;
+        if (listeners == null || !listeners.containsListener(key, propertyMap)) {
+            newListeners = new PropertyListeners(listeners);
+            newListeners.addListener(key, propertyMap);
+            return newListeners;
+        }
+        return listeners;
+    }
+
+    /**
+     * Checks whether {@code propertyMap} is registered as listener with {@code key}.
+     *
+     * @param key the property key
+     * @param propertyMap the property map
+     * @return true if property map is registered with property key
+     */
+    synchronized boolean containsListener(final String key, final PropertyMap propertyMap) {
+        if (listeners == null) {
+            return false;
+        }
+        WeakPropertyMapSet set = listeners.get(key);
+        return set != null && set.contains(propertyMap);
+    }
+
+    /**
+     * Add a property listener to this object.
+     *
+     * @param propertyMap The property listener that is added.
+     */
+    synchronized final void addListener(final String key, final PropertyMap propertyMap) {
+        if (Context.DEBUG) {
+            listenersAdded++;
+        }
+        if (listeners == null) {
+            listeners = new WeakHashMap<>();
+        }
+
+        WeakPropertyMapSet set = listeners.get(key);
+        if (set == null) {
+            set = new WeakPropertyMapSet();
+            listeners.put(key, set);
+        }
+        if (!set.contains(propertyMap)) {
+            set.add(propertyMap);
+        }
+    }
+
+    /**
+     * A new property is being added.
+     *
+     * @param prop The new Property added.
+     */
+    public synchronized void propertyAdded(final Property prop) {
+        if (listeners != null) {
+            WeakPropertyMapSet set = listeners.get(prop.getKey());
+            if (set != null) {
+                for (PropertyMap propertyMap : set.elements()) {
+                    propertyMap.propertyAdded(prop);
+                }
+                listeners.remove(prop.getKey());
+            }
+        }
+    }
+
+    /**
+     * An existing property is being deleted.
+     *
+     * @param prop The property being deleted.
+     */
+    public synchronized void propertyDeleted(final Property prop) {
+        if (listeners != null) {
+            WeakPropertyMapSet set = listeners.get(prop.getKey());
+            if (set != null) {
+                for (PropertyMap propertyMap : set.elements()) {
+                    propertyMap.propertyDeleted(prop);
+                }
+                listeners.remove(prop.getKey());
+            }
+        }
+    }
+
+    /**
+     * An existing Property is being replaced with a new Property.
+     *
+     * @param oldProp The old property that is being replaced.
+     * @param newProp The new property that replaces the old property.
+     *
+     */
+    public synchronized void propertyModified(final Property oldProp, final Property newProp) {
+        if (listeners != null) {
+            WeakPropertyMapSet set = listeners.get(oldProp.getKey());
+            if (set != null) {
+                for (PropertyMap propertyMap : set.elements()) {
+                    propertyMap.propertyModified(oldProp, newProp);
+                }
+                listeners.remove(oldProp.getKey());
+            }
+        }
+    }
+
+    public synchronized void protoChanged() {
+        if (listeners != null) {
+            for (WeakPropertyMapSet set : listeners.values()) {
+                for (PropertyMap propertyMap : set.elements()) {
+                    propertyMap.protoChanged();
+                }
+            }
+            listeners.clear();
+        }
+    }
+
+    private static class WeakPropertyMapSet {
+
+        private WeakHashMap<PropertyMap, Boolean> map = new WeakHashMap<>();
+
+        void add(final PropertyMap propertyMap) {
+            map.put(propertyMap, Boolean.TRUE);
+        }
+
+        boolean contains(final PropertyMap propertyMap) {
+            return map.containsKey(propertyMap);
+        }
+
+        Set<PropertyMap> elements() {
+            return map.keySet();
+        }
+
+    }
+}
--- a/src/jdk/nashorn/internal/runtime/PropertyMap.java	Thu Mar 20 16:26:54 2014 +0100
+++ b/src/jdk/nashorn/internal/runtime/PropertyMap.java	Fri Mar 21 17:52:03 2014 +0100
@@ -30,13 +30,11 @@
 import static jdk.nashorn.internal.runtime.arrays.ArrayIndex.isValidArrayIndex;
 
 import java.lang.invoke.SwitchPoint;
-import java.lang.ref.WeakReference;
+import java.lang.ref.SoftReference;
 import java.util.Arrays;
 import java.util.Collection;
 import java.util.HashMap;
 import java.util.Iterator;
-import java.util.LinkedHashMap;
-import java.util.Map;
 import java.util.NoSuchElementException;
 import java.util.WeakHashMap;
 
@@ -49,17 +47,11 @@
  * All property maps are immutable. If a property is added, modified or removed, the mutator
  * will return a new map.
  */
-public final class PropertyMap implements Iterable<Object>, PropertyListener {
+public final class PropertyMap implements Iterable<Object> {
     /** Used for non extensible PropertyMaps, negative logic as the normal case is extensible. See {@link ScriptObject#preventExtensions()} */
     public static final int NOT_EXTENSIBLE        = 0b0000_0001;
     /** Does this map contain valid array keys? */
     public static final int CONTAINS_ARRAY_KEYS   = 0b0000_0010;
-    /** This mask is used to preserve certain flags when cloning the PropertyMap. Others should not be copied */
-    private static final int CLONEABLE_FLAGS_MASK = 0b0000_1111;
-    /** Has a listener been added to this property map. This flag is not copied when cloning a map. See {@link PropertyListener} */
-    public static final int IS_LISTENER_ADDED     = 0b0001_0000;
-    /** Is this process wide "shared" map?. This flag is not copied when cloning a map */
-    public static final int IS_SHARED             = 0b0010_0000;
 
     /** Map status flags. */
     private int flags;
@@ -77,16 +69,16 @@
     private int spillLength;
 
     /** {@link SwitchPoint}s for gets on inherited properties. */
-    private Map<String, SwitchPoint> protoGetSwitches;
+    private HashMap<String, SwitchPoint> protoGetSwitches;
 
     /** History of maps, used to limit map duplication. */
-    private HashMap<Property, PropertyMap> history;
+    private WeakHashMap<Property, SoftReference<PropertyMap>> history;
 
     /** History of prototypes, used to limit map duplication. */
-    private WeakHashMap<ScriptObject, WeakReference<PropertyMap>> protoHistory;
+    private WeakHashMap<PropertyMap, SoftReference<PropertyMap>> protoHistory;
 
-    /** Cache for hashCode */
-    private int hashCode;
+    /** property listeners */
+    private PropertyListeners listeners;
 
     /**
      * Constructor.
@@ -119,10 +111,12 @@
      */
     private PropertyMap(final PropertyMap propertyMap, final PropertyHashMap properties) {
         this.properties   = properties;
-        this.flags        = propertyMap.getClonedFlags();
+        this.flags        = propertyMap.flags;
         this.spillLength  = propertyMap.spillLength;
         this.fieldCount   = propertyMap.fieldCount;
         this.fieldMaximum = propertyMap.fieldMaximum;
+        // We inherit the parent property listeners instance. It will be cloned when a new listener is added.
+        this.listeners    = propertyMap.listeners;
 
         if (Context.DEBUG) {
             count++;
@@ -203,35 +197,92 @@
     }
 
     /**
+     * Get the listeners of this map, or null if none exists
+     *
+     * @return the listeners
+     */
+    public PropertyListeners getListeners() {
+        return listeners;
+    }
+
+    /**
+     * Add {@code listenerMap} as a listener to this property map for the given {@code key}.
+     *
+     * @param key the property name
+     * @param listenerMap the listener map
+     */
+    public void addListener(final String key, final PropertyMap listenerMap) {
+        if (listenerMap != this) {
+            // We need to clone listener instance when adding a new listener since we share
+            // the listeners instance with our parent maps that don't need to see the new listener.
+            listeners = PropertyListeners.addListener(listeners, key, listenerMap);
+        }
+    }
+
+    /**
+     * A new property is being added.
+     *
+     * @param property The new Property added.
+     */
+    public void propertyAdded(final Property property) {
+        invalidateProtoGetSwitchPoint(property);
+        if (listeners != null) {
+            listeners.propertyAdded(property);
+        }
+    }
+
+    /**
+     * An existing property is being deleted.
+     *
+     * @param property The property being deleted.
+     */
+    public void propertyDeleted(final Property property) {
+        invalidateProtoGetSwitchPoint(property);
+        if (listeners != null) {
+            listeners.propertyDeleted(property);
+        }
+    }
+
+    /**
+     * An existing property is being redefined.
+     *
+     * @param oldProperty The old property
+     * @param newProperty The new property
+     */
+    public void propertyModified(final Property oldProperty, final Property newProperty) {
+        invalidateProtoGetSwitchPoint(oldProperty);
+        if (listeners != null) {
+            listeners.propertyModified(oldProperty, newProperty);
+        }
+    }
+
+    /**
+     * The prototype of an object associated with this {@link PropertyMap} is changed.
+     */
+    public void protoChanged() {
+        invalidateAllProtoGetSwitchPoints();
+        if (listeners != null) {
+            listeners.protoChanged();
+        }
+    }
+
+    /**
      * Return a SwitchPoint used to track changes of a property in a prototype.
      *
-     * @param proto  Object prototype.
-     * @param key    {@link Property} key.
-     *
+     * @param key Property key.
      * @return A shared {@link SwitchPoint} for the property.
      */
-    public SwitchPoint getProtoGetSwitchPoint(final ScriptObject proto, final String key) {
-        assert !isShared() : "proto SwitchPoint from a shared PropertyMap";
-
-        if (proto == null) {
-            return null;
+    public synchronized SwitchPoint getSwitchPoint(final String key) {
+        if (protoGetSwitches == null) {
+            protoGetSwitches = new HashMap<>();
         }
 
-        if (protoGetSwitches == null) {
-            protoGetSwitches = new HashMap<>();
-            if (! isListenerAdded()) {
-                proto.addPropertyListener(this);
-                setIsListenerAdded();
-            }
+        SwitchPoint switchPoint = protoGetSwitches.get(key);
+        if (switchPoint == null) {
+            switchPoint = new SwitchPoint();
+            protoGetSwitches.put(key, switchPoint);
         }
 
-        if (protoGetSwitches.containsKey(key)) {
-            return protoGetSwitches.get(key);
-        }
-
-        final SwitchPoint switchPoint = new SwitchPoint();
-        protoGetSwitches.put(key, switchPoint);
-
         return switchPoint;
     }
 
@@ -240,14 +291,13 @@
      *
      * @param property {@link Property} to invalidate.
      */
-    private void invalidateProtoGetSwitchPoint(final Property property) {
-        assert !isShared() : "proto invalidation on a shared PropertyMap";
+    synchronized void invalidateProtoGetSwitchPoint(final Property property) {
+        if (protoGetSwitches != null) {
 
-        if (protoGetSwitches != null) {
             final String key = property.getKey();
             final SwitchPoint sp = protoGetSwitches.get(key);
             if (sp != null) {
-                protoGetSwitches.put(key, new SwitchPoint());
+                protoGetSwitches.remove(key);
                 if (Context.DEBUG) {
                     protoInvalidations++;
                 }
@@ -257,14 +307,15 @@
     }
 
     /**
-     * Indicate that proto itself has changed in hierachy somewhere.
+     * Indicate that proto itself has changed in hierarchy somewhere.
      */
-    private void invalidateAllProtoGetSwitchPoints() {
-        assert !isShared() : "proto invalidation on a shared PropertyMap";
-
-        if (protoGetSwitches != null) {
-            final Collection<SwitchPoint> sws = protoGetSwitches.values();
-            SwitchPoint.invalidateAll(sws.toArray(new SwitchPoint[sws.size()]));
+    synchronized void invalidateAllProtoGetSwitchPoints() {
+        if (protoGetSwitches != null && !protoGetSwitches.isEmpty()) {
+            if (Context.DEBUG) {
+                protoInvalidations += protoGetSwitches.size();
+            }
+            SwitchPoint.invalidateAll(protoGetSwitches.values().toArray(new SwitchPoint[protoGetSwitches.values().size()]));
+            protoGetSwitches.clear();
         }
     }
 
@@ -279,7 +330,33 @@
      * @return New {@link PropertyMap} with {@link Property} added.
      */
     PropertyMap addPropertyBind(final AccessorProperty property, final Object bindTo) {
-        return addProperty(new AccessorProperty(property, bindTo));
+        // No need to store bound property in the history as bound properties can't be reused.
+        return addPropertyNoHistory(new AccessorProperty(property, bindTo));
+    }
+
+    /**
+     * Add a property to the map without adding it to the history. This should be used for properties that
+     * can't be shared such as bound properties, or properties that are expected to be added only once.
+     *
+     * @param property {@link Property} being added.
+     * @return New {@link PropertyMap} with {@link Property} added.
+     */
+    public PropertyMap addPropertyNoHistory(final Property property) {
+        if (listeners != null) {
+            listeners.propertyAdded(property);
+        }
+        final PropertyHashMap newProperties = properties.immutableAdd(property);
+        final PropertyMap newMap = new PropertyMap(this, newProperties);
+
+        if(!property.isSpill()) {
+            newMap.fieldCount = Math.max(newMap.fieldCount, property.getSlot() + 1);
+        }
+        if (isValidArrayIndex(getArrayIndex(property.getKey()))) {
+            newMap.setContainsArrayKeys();
+        }
+
+        newMap.spillLength += property.getSpillCount();
+        return newMap;
     }
 
     /**
@@ -290,6 +367,9 @@
      * @return New {@link PropertyMap} with {@link Property} added.
      */
     public PropertyMap addProperty(final Property property) {
+        if (listeners != null) {
+            listeners.propertyAdded(property);
+        }
         PropertyMap newMap = checkHistory(property);
 
         if (newMap == null) {
@@ -318,6 +398,9 @@
      * @return New {@link PropertyMap} with {@link Property} removed or {@code null} if not found.
      */
     public PropertyMap deleteProperty(final Property property) {
+        if (listeners != null) {
+            listeners.propertyDeleted(property);
+        }
         PropertyMap newMap = checkHistory(property);
         final String key = property.getKey();
 
@@ -339,6 +422,10 @@
      * @return New {@link PropertyMap} with {@link Property} replaced.
      */
     PropertyMap replaceProperty(final Property oldProperty, final Property newProperty) {
+        if (listeners != null) {
+            listeners.propertyModified(oldProperty, newProperty);
+        }
+        // Add replaces existing property.
         final PropertyHashMap newProperties = properties.immutableReplace(oldProperty, newProperty);
         final PropertyMap newMap = new PropertyMap(this, newProperties);
         /*
@@ -362,7 +449,7 @@
                 newProperty instanceof UserAccessorProperty :
             "arbitrary replaceProperty attempted " + sameType + " oldProperty=" + oldProperty.getClass() + " newProperty=" + newProperty.getClass() + " [" + oldProperty.getCurrentType() + " => " + newProperty.getCurrentType() + "]";
 
-        newMap.flags = getClonedFlags();
+        newMap.flags = flags;
 
         /*
          * spillLength remains same in case (1) and (2) because of slot reuse. Only for case (3), we need
@@ -485,28 +572,6 @@
     }
 
     /**
-     * Make this property map 'shared' one. Shared property map instances are
-     * process wide singleton objects. A shaped map should never be added as a listener
-     * to a proto object. Nor it should have history or proto history. A shared map
-     * is just a template that is meant to be duplicated before use. All nasgen initialized
-     * property maps are shared.
-     *
-     * @return this map after making it as shared
-     */
-    public PropertyMap setIsShared() {
-        assert !isListenerAdded() : "making PropertyMap shared after listener added";
-        assert protoHistory == null : "making PropertyMap shared after associating a proto with it";
-        if (Context.DEBUG) {
-            sharedCount++;
-        }
-
-        flags |= IS_SHARED;
-        // clear any history on this PropertyMap, won't be used.
-        history = null;
-        return this;
-    }
-
-    /**
      * Check for any configurable properties.
      *
      * @return {@code true} if any configurable.
@@ -545,15 +610,15 @@
     /**
      * Check prototype history for an existing property map with specified prototype.
      *
-     * @param newProto New prototype object.
+     * @param parentMap New prototype object.
      *
      * @return Existing {@link PropertyMap} or {@code null} if not found.
      */
-    private PropertyMap checkProtoHistory(final ScriptObject newProto) {
+    private PropertyMap checkProtoHistory(final PropertyMap parentMap) {
         final PropertyMap cachedMap;
         if (protoHistory != null) {
-            final WeakReference<PropertyMap> weakMap = protoHistory.get(newProto);
-            cachedMap = weakMap != null ? weakMap.get() : null;
+            final SoftReference<PropertyMap> weakMap = protoHistory.get(parentMap);
+            cachedMap = (weakMap != null ? weakMap.get() : null);
         } else {
             cachedMap = null;
         }
@@ -568,17 +633,15 @@
     /**
      * Add a map to the prototype history.
      *
-     * @param newProto Prototype to add (key.)
+     * @param parentMap Prototype to add (key.)
      * @param newMap   {@link PropertyMap} associated with prototype.
      */
-    private void addToProtoHistory(final ScriptObject newProto, final PropertyMap newMap) {
-        assert !isShared() : "proto history modified on a shared PropertyMap";
-
+    private void addToProtoHistory(final PropertyMap parentMap, final PropertyMap newMap) {
         if (protoHistory == null) {
             protoHistory = new WeakHashMap<>();
         }
 
-        protoHistory.put(newProto, new WeakReference<>(newMap));
+        protoHistory.put(parentMap, new SoftReference<>(newMap));
     }
 
     /**
@@ -588,14 +651,12 @@
      * @param newMap   Modified {@link PropertyMap}.
      */
     private void addToHistory(final Property property, final PropertyMap newMap) {
-        assert !isShared() : "history modified on a shared PropertyMap";
-
         if (!properties.isEmpty()) {
             if (history == null) {
-                history = new LinkedHashMap<>();
+                history = new WeakHashMap<>();
             }
 
-            history.put(property, newMap);
+            history.put(property, new SoftReference<>(newMap));
         }
     }
 
@@ -607,8 +668,10 @@
      * @return Existing map or {@code null} if not found.
      */
     private PropertyMap checkHistory(final Property property) {
+
         if (history != null) {
-            final PropertyMap historicMap = history.get(property);
+            final SoftReference<PropertyMap> ref = history.get(property);
+            final PropertyMap historicMap = ref == null ? null : ref.get();
 
             if (historicMap != null) {
                 if (Context.DEBUG) {
@@ -623,54 +686,6 @@
     }
 
     /**
-     * Calculate the hash code for the map.
-     *
-     * @return Computed hash code.
-     */
-    private int computeHashCode() {
-        int hash = 0;
-
-        for (final Property property : getProperties()) {
-            hash = hash << 7 ^ hash >> 7;
-            hash ^= property.hashCode();
-        }
-
-        return hash;
-    }
-
-    @Override
-    public int hashCode() {
-        if (hashCode == 0 && !properties.isEmpty()) {
-            hashCode = computeHashCode();
-        }
-        return hashCode;
-    }
-
-    @Override
-    public boolean equals(final Object other) {
-        if (!(other instanceof PropertyMap)) {
-            return false;
-        }
-
-        final PropertyMap otherMap = (PropertyMap)other;
-
-        if (properties.size() != otherMap.properties.size()) {
-            return false;
-        }
-
-        final Iterator<Property> iter      = properties.values().iterator();
-        final Iterator<Property> otherIter = otherMap.properties.values().iterator();
-
-        while (iter.hasNext() && otherIter.hasNext()) {
-            if (!iter.next().equals(otherIter.next())) {
-                return false;
-            }
-        }
-
-        return true;
-    }
-
-    /**
      * Returns true if the two maps have identical properties in the same order, but allows the properties to differ in
      * their types. This method is mostly useful for tests.
      * @param otherMap the other map
@@ -734,24 +749,6 @@
     }
 
     /**
-     * Check whether a {@link PropertyListener} has been added to this map.
-     *
-     * @return {@code true} if {@link PropertyListener} exists
-     */
-    public boolean isListenerAdded() {
-        return (flags & IS_LISTENER_ADDED) != 0;
-    }
-
-    /**
-     * Check if this map shared or not.
-     *
-     * @return true if this map is shared.
-     */
-    public boolean isShared() {
-        return (flags & IS_SHARED) != 0;
-    }
-
-    /**
      * Test to see if {@link PropertyMap} is extensible.
      *
      * @return {@code true} if {@link PropertyMap} can be added to.
@@ -806,50 +803,29 @@
     }
 
     /**
-     * Change the prototype of objects associated with this {@link PropertyMap}.
+     * Return a property map with the same layout that is associated with the new prototype object.
      *
-     * @param oldProto Current prototype object.
      * @param newProto New prototype object to replace oldProto.
-     *
      * @return New {@link PropertyMap} with prototype changed.
      */
-    PropertyMap changeProto(final ScriptObject oldProto, final ScriptObject newProto) {
-        assert !isShared() : "proto associated with a shared PropertyMap";
+    public PropertyMap changeProto(final ScriptObject newProto) {
 
-        if (oldProto == newProto) {
-            return this;
-        }
-
-        final PropertyMap nextMap = checkProtoHistory(newProto);
+        final PropertyMap parentMap = newProto == null ? null : newProto.getMap();
+        final PropertyMap nextMap = checkProtoHistory(parentMap);
         if (nextMap != null) {
             return nextMap;
         }
 
         if (Context.DEBUG) {
-            incrementSetProtoNewMapCount();
+            setProtoNewMapCount++;
         }
 
         final PropertyMap newMap = new PropertyMap(this);
-        addToProtoHistory(newProto, newMap);
+        addToProtoHistory(parentMap, newMap);
 
         return newMap;
     }
 
-    /**
-     * Indicate that the map has listeners.
-     */
-    private void setIsListenerAdded() {
-        flags |= IS_LISTENER_ADDED;
-    }
-
-    /**
-     * Return only the flags that should be copied during cloning.
-     *
-     * @return Subset of flags that should be copied.
-     */
-    private int getClonedFlags() {
-        return flags & CLONEABLE_FLAGS_MASK;
-    }
 
     /**
      * {@link PropertyMap} iterator.
@@ -906,34 +882,6 @@
     }
 
     /*
-     * PropertyListener implementation.
-     */
-
-    @Override
-    public void propertyAdded(final ScriptObject object, final Property prop) {
-        invalidateProtoGetSwitchPoint(prop);
-    }
-
-    @Override
-    public void propertyDeleted(final ScriptObject object, final Property prop) {
-        invalidateProtoGetSwitchPoint(prop);
-    }
-
-    @Override
-    public void propertyModified(final ScriptObject object, final Property oldProp, final Property newProp) {
-        invalidateProtoGetSwitchPoint(oldProp);
-    }
-
-    @Override
-    public void protoChanged(final ScriptObject object, final ScriptObject oldProto, final ScriptObject newProto) {
-        // We may walk and invalidate SwitchPoints for properties inherited
-        // from 'object' or it's old proto chain. But, it may not be worth it.
-        // For example, a new proto may have a user defined getter/setter for
-        // a data property down the chain. So, invalidating all is better.
-        invalidateAllProtoGetSwitchPoints();
-    }
-
-    /*
      * Debugging and statistics.
      */
 
@@ -991,7 +939,6 @@
     // counters updated only in debug mode
     private static int count;
     private static int clonedCount;
-    private static int sharedCount;
     private static int duplicatedCount;
     private static int historyHit;
     private static int protoInvalidations;
@@ -1013,13 +960,6 @@
     }
 
     /**
-     * @return The number of maps that are shared.
-     */
-    public static int getSharedCount() {
-        return sharedCount;
-    }
-
-    /**
      * @return The number of maps that are duplicated.
      */
     public static int getDuplicatedCount() {
@@ -1053,12 +993,4 @@
     public static int getSetProtoNewMapCount() {
         return setProtoNewMapCount;
     }
-
-    /**
-     * Increment the prototype set count.
-     */
-    private static void incrementSetProtoNewMapCount() {
-        setProtoNewMapCount++;
-    }
-
 }
--- a/src/jdk/nashorn/internal/runtime/RecompilableScriptFunctionData.java	Thu Mar 20 16:26:54 2014 +0100
+++ b/src/jdk/nashorn/internal/runtime/RecompilableScriptFunctionData.java	Fri Mar 21 17:52:03 2014 +0100
@@ -36,7 +36,6 @@
 import java.util.Map;
 import java.util.Set;
 import java.util.concurrent.atomic.AtomicInteger;
-
 import jdk.internal.dynalink.support.NameCodec;
 import jdk.nashorn.internal.codegen.CompilationEnvironment;
 import jdk.nashorn.internal.codegen.CompilationEnvironment.CompilationPhases;
@@ -139,10 +138,7 @@
 
         super(functionName(functionNode),
               Math.min(functionNode.getParameters().size(), MAX_ARITY),
-              functionNode.isStrict(),
-              false,
-              true,
-              functionNode.isVarArg());
+              getFlags(functionNode));
 
         this.functionName        = functionNode.getName();
         this.lineNumber          = functionNode.getLineNumber();
@@ -243,11 +239,33 @@
         return Token.toDesc(TokenType.FUNCTION, position, length);
     }
 
+    private static int getFlags(final FunctionNode functionNode) {
+        int flags = IS_CONSTRUCTOR;
+        if (functionNode.isStrict()) {
+            flags |= IS_STRICT;
+        }
+        if (functionNode.needsCallee()) {
+            flags |= NEEDS_CALLEE;
+        }
+        if (functionNode.usesThis() || functionNode.hasEval()) {
+            flags |= USES_THIS;
+        }
+        if (functionNode.isVarArg()) {
+            flags |= IS_VARIABLE_ARITY;
+        }
+        return flags;
+    }
+
     @Override
-    ScriptObject allocate() {
+    PropertyMap getAllocatorMap() {
+        return allocatorMap;
+    }
+
+    @Override
+    ScriptObject allocate(final PropertyMap map) {
         try {
             ensureHasAllocator(); //if allocatorClass name is set to null (e.g. for bound functions) we don't even try
-            return allocator == null ? null : (ScriptObject)allocator.invokeExact(allocatorMap);
+            return allocator == null ? null : (ScriptObject)allocator.invokeExact(map);
         } catch (final RuntimeException | Error e) {
             throw e;
         } catch (final Throwable t) {
--- a/src/jdk/nashorn/internal/runtime/ScriptFunction.java	Thu Mar 20 16:26:54 2014 +0100
+++ b/src/jdk/nashorn/internal/runtime/ScriptFunction.java	Fri Mar 21 17:52:03 2014 +0100
@@ -68,6 +68,8 @@
 
     private static final MethodHandle WRAPFILTER = findOwnMH_S("wrapFilter", Object.class, Object.class);
 
+    private static final MethodHandle GLOBALFILTER = findOwnMH_S("globalFilter", Object.class, Object.class);
+
     /** method handle to scope getter for this ScriptFunction */
     public static final Call GET_SCOPE = virtualCallNoLookup(ScriptFunction.class, "getScope", ScriptObject.class);
 
@@ -86,6 +88,9 @@
 
     private final ScriptFunctionData data;
 
+    /** The property map used for newly allocated object when function is used as constructor. */
+    protected PropertyMap allocatorMap;
+
     /**
      * Constructor
      *
@@ -94,9 +99,7 @@
      * @param map           property map
      * @param scope         scope
      * @param specs         specialized version of this function - other method handles
-     * @param strict        is this a strict mode function?
-     * @param builtin       is this a built in function?
-     * @param isConstructor is this a constructor?
+     * @param flags         {@link ScriptFunctionData} flags
      */
     protected ScriptFunction(
             final String name,
@@ -104,11 +107,9 @@
             final PropertyMap map,
             final ScriptObject scope,
             final MethodHandle[] specs,
-            final boolean strict,
-            final boolean builtin,
-            final boolean isConstructor) {
+            final int flags) {
 
-        this(new FinalScriptFunctionData(name, methodHandle, specs, strict, builtin, isConstructor), map, scope);
+        this(new FinalScriptFunctionData(name, methodHandle, specs, flags), map, scope);
     }
 
     /**
@@ -131,6 +132,7 @@
 
         this.data  = data;
         this.scope = scope;
+        this.allocatorMap = data.getAllocatorMap();
     }
 
     @Override
@@ -240,16 +242,16 @@
 
         assert !isBoundFunction(); // allocate never invoked on bound functions
 
-        final ScriptObject object = data.allocate();
+        final ScriptObject object = data.allocate(allocatorMap);
 
         if (object != null) {
             final Object prototype = getPrototype();
             if (prototype instanceof ScriptObject) {
-                object.setProto((ScriptObject)prototype);
+                object.setInitialProto((ScriptObject)prototype);
             }
 
             if (object.getProto() == null) {
-                object.setProto(getObjectPrototype());
+                object.setInitialProto(getObjectPrototype());
             }
         }
 
@@ -479,7 +481,14 @@
         if (obj instanceof ScriptObject || !ScriptFunctionData.isPrimitiveThis(obj)) {
             return obj;
         }
-        return ((GlobalObject)Context.getGlobalTrusted()).wrapAsObject(obj);
+        return Context.getGlobal().wrapAsObject(obj);
+    }
+
+
+    @SuppressWarnings("unused")
+    private static Object globalFilter(final Object object) {
+        // replace whatever we get with the current global object
+        return Context.getGlobal();
     }
 
     /**
@@ -541,11 +550,11 @@
         final int programPoint = NashornCallSiteDescriptor.isOptimistic(desc) ? NashornCallSiteDescriptor.getProgramPoint(desc) : INVALID_PROGRAM_POINT;
         final GuardedInvocation bestInvoker = getBestInvoker(type, programPoint);
         final MethodHandle callHandle = bestInvoker.getInvocation();
+
         if (data.needsCallee()) {
-            if (scopeCall) {
-                // Make a handle that drops the passed "this" argument and binds either Global or Undefined instead
-                // Signature remains (callee, this, args...)
-                boundHandle = MH.dropArguments(bindImplicitThis(callHandle), 1, type.parameterType(1));
+            if (scopeCall && needsWrappedThis()) {
+                // (callee, this, args...) => (callee, [this], args...)
+                boundHandle = MH.filterArguments(callHandle, 1, GLOBALFILTER);
             } else {
                 // It's already (callee, this, args...), just what we need
                 boundHandle = callHandle;
@@ -554,11 +563,12 @@
             // NOTE: the only built-in named "extend" is NativeJava.extend. As a special-case we're binding the
             // current lookup as its "this" so it can do security-sensitive creation of adapter classes.
             boundHandle = MH.dropArguments(MH.bindTo(callHandle, desc.getLookup()), 0, type.parameterType(0), type.parameterType(1));
-        } else if (scopeCall) {
+        } else if (scopeCall && needsWrappedThis()) {
             // Make a handle that drops the passed "this" argument and substitutes either Global or Undefined
-            // (this, args...) => (args...)
-            // (args...) => ([callee], [this], args...)
-            boundHandle = MH.dropArguments(MH.bindTo(callHandle, getImplicitThis()), 0, type.parameterType(0), type.parameterType(1));
+            // (this, args...) => ([this], args...)
+            boundHandle = MH.filterArguments(callHandle, 0, GLOBALFILTER);
+            // ([this], args...) => ([callee], [this], args...)
+            boundHandle = MH.dropArguments(boundHandle, 0, type.parameterType(0));
         } else {
             // (this, args...) => ([callee], this, args...)
             boundHandle = MH.dropArguments(callHandle, 0, type.parameterType(0));
@@ -672,18 +682,15 @@
     }
 
      private static MethodHandle bindImplicitThis(final Object fn, final MethodHandle mh) {
-         return MH.insertArguments(mh, 1, fn instanceof ScriptFunction ? ((ScriptFunction)fn).getImplicitThis() : ScriptRuntime.UNDEFINED);
+         final MethodHandle bound;
+         if(fn instanceof ScriptFunction && ((ScriptFunction)fn).needsWrappedThis()) {
+             bound = MH.filterArguments(mh, 1, GLOBALFILTER);
+         } else {
+             bound = mh;
+         }
+         return MH.insertArguments(bound, 1, ScriptRuntime.UNDEFINED);
      }
 
-     private MethodHandle bindImplicitThis(final MethodHandle mh) {
-         return MH.insertArguments(mh, 1, getImplicitThis());
-     }
-
-    private Object getImplicitThis() {
-        return needsWrappedThis() ? Context.getGlobalTrusted() : ScriptRuntime.UNDEFINED;
-    }
-
-
     /**
      * Used for noSuchMethod/noSuchProperty and JSAdapter hooks.
      *
--- a/src/jdk/nashorn/internal/runtime/ScriptFunctionData.java	Thu Mar 20 16:26:54 2014 +0100
+++ b/src/jdk/nashorn/internal/runtime/ScriptFunctionData.java	Fri Mar 21 17:52:03 2014 +0100
@@ -37,7 +37,6 @@
 import java.util.Collections;
 import java.util.Map;
 import java.util.WeakHashMap;
-
 import jdk.internal.dynalink.linker.GuardedInvocation;
 import jdk.nashorn.internal.runtime.linker.JavaAdapterFactory;
 import jdk.nashorn.internal.runtime.linker.LinkerCallSite;
@@ -65,46 +64,56 @@
     // TODO: integrate it into ScriptFunctionData; there's not much reason for this to be in its own class.
     protected final CompiledFunctions code;
 
+    /** Function flags */
+    protected int flags;
+
     // Parameter arity of the function, corresponding to "f.length". E.g. "function f(a, b, c) { ... }" arity is 3, and
     // some built-in ECMAScript functions have their arity declared by the specification. Note that regardless of this
     // value, the function might still be capable of receiving variable number of arguments, see isVariableArity.
-    private byte arity;
-
-    private final boolean isStrict;
-    private final boolean isBuiltin;
-    private final boolean isConstructor;
-    private final boolean isVariableArity;
+    private int arity;
 
     private static final MethodHandle BIND_VAR_ARGS = findOwnMH("bindVarArgs", Object[].class, Object[].class, Object[].class);
 
+    /** Is this a strict mode function? */
+    public static final int IS_STRICT      = 1 << 0;
+    /** Is this a built-in function? */
+    public static final int IS_BUILTIN     = 1 << 1;
+    /** Is this a constructor function? */
+    public static final int IS_CONSTRUCTOR = 1 << 2;
+    /** Does this function expect a callee argument? */
+    public static final int NEEDS_CALLEE   = 1 << 3;
+    /** Does this function make use of the this-object argument? */
+    public static final int USES_THIS      = 1 << 4;
+    /** Is this a variable arity function? */
+    public static final int IS_VARIABLE_ARITY = 1 << 5;
+
+    /** Flag for strict or built-in functions */
+    public static final int IS_STRICT_OR_BUILTIN = IS_STRICT | IS_BUILTIN;
+    /** Flag for built-in constructors */
+    public static final int IS_BUILTIN_CONSTRUCTOR = IS_BUILTIN | IS_CONSTRUCTOR;
+    /** Flag for strict constructors */
+    public static final int IS_STRICT_CONSTRUCTOR = IS_STRICT | IS_CONSTRUCTOR;
+
     /**
      * Constructor
      *
-     * @param name          script function name
-     * @param arity         arity
-     * @param isStrict      is the function strict
-     * @param isBuiltin     is the function built in
-     * @param isConstructor is the function a constructor
+     * @param name  script function name
+     * @param arity arity
+     * @param flags the function flags
      */
-    ScriptFunctionData(final String name, final int arity, final boolean isStrict, final boolean isBuiltin,
-            final boolean isConstructor, final boolean isVariableArity) {
-        this.name            = name;
-        this.code            = new CompiledFunctions(name);
-        this.isStrict        = isStrict;
-        this.isBuiltin       = isBuiltin;
-        this.isConstructor   = isConstructor;
-        this.isVariableArity = isVariableArity;
-
+    ScriptFunctionData(final String name, final int arity, final int flags) {
+        this.name  = name;
+        this.code  = new CompiledFunctions(name);
+        this.flags = flags;
         setArity(arity);
     }
 
     final int getArity() {
-        // arity byte should be interpreted as u8.
-        return arity & 0xFF;
+        return arity;
     }
 
     final boolean isVariableArity() {
-        return isVariableArity;
+        return (flags & IS_VARIABLE_ARITY) != 0;
     }
 
     /**
@@ -115,7 +124,7 @@
         if(arity < 0 || arity > MAX_ARITY) {
             throw new IllegalArgumentException(String.valueOf(arity));
         }
-        this.arity = (byte)arity;
+        this.arity = arity;
     }
 
     CompiledFunction bind(final CompiledFunction originalInv, final ScriptFunction fn, final Object self, final Object[] args) {
@@ -133,15 +142,15 @@
      * @return true if strict, false otherwise
      */
     public boolean isStrict() {
-        return isStrict;
+        return (flags & IS_STRICT) != 0;
     }
 
     boolean isBuiltin() {
-        return isBuiltin;
+        return (flags & IS_BUILTIN) != 0;
     }
 
     boolean isConstructor() {
-        return isConstructor;
+        return (flags & IS_CONSTRUCTOR) != 0;
     }
 
     abstract boolean needsCallee();
@@ -152,7 +161,7 @@
      * @return true if this argument must be an object
      */
     boolean needsWrappedThis() {
-        return !isStrict && !isBuiltin;
+        return (flags & USES_THIS) != 0 && (flags & IS_STRICT_OR_BUILTIN) == 0;
     }
 
     String toSource() {
@@ -210,6 +219,15 @@
     }
 
     /**
+     * If we can have lazy code generation, this is a hook to ensure that the code has been compiled.
+     * This does not guarantee the code been installed in this {@code ScriptFunctionData} instance;
+     * use {@link #ensureCodeGenerated()} to install the actual method handles.
+     */
+    protected void ensureCompiled() {
+        //empty
+    }
+
+    /**
      * Return a generic Object/Object invoker for this method. It will ensure code
      * is generated, get the most generic of all versions of this function and adapt it
      * to Objects.
@@ -276,9 +294,20 @@
 
     /**
      * Allocates an object using this function's allocator.
+     *
+     * @param map the property map for the allocated object.
      * @return the object allocated using this function's allocator, or null if the function doesn't have an allocator.
      */
-    ScriptObject allocate() {
+    ScriptObject allocate(final PropertyMap map) {
+        return null;
+    }
+
+    /**
+     * Get the property map to use for objects allocated by this function.
+     *
+     * @return the property map for allocated objects.
+     */
+    PropertyMap getAllocatorMap() {
         return null;
     }
 
@@ -293,13 +322,14 @@
     ScriptFunctionData makeBoundFunctionData(final ScriptFunction fn, final Object self, final Object[] args) {
         final Object[] allArgs = args == null ? ScriptRuntime.EMPTY_ARRAY : args;
         final int length = args == null ? 0 : args.length;
+        // Clear the callee and this flags
+        final int boundFlags = flags & ~NEEDS_CALLEE & ~USES_THIS;
 
         final CompiledFunctions boundList = new CompiledFunctions(fn.getName());
         final CompiledFunction bindTarget = new CompiledFunction(getGenericInvoker(), getGenericConstructor());
         boundList.add(bind(bindTarget, fn, self, allArgs));
 
-        final ScriptFunctionData boundData = new FinalScriptFunctionData(name, Math.max(0, getArity() - length), boundList, isStrict(), isBuiltin(), isConstructor(), isVariableArity());
-        return boundData;
+        return new FinalScriptFunctionData(name, Math.max(0, getArity() - length), boundList, boundFlags);
     }
 
     /**
@@ -316,11 +346,11 @@
     static Object wrapThis(final Object thiz) {
         if (!(thiz instanceof ScriptObject)) {
             if (JSType.nullOrUndefined(thiz)) {
-                return Context.getGlobalTrusted();
+                return Context.getGlobal();
             }
 
             if (isPrimitiveThis(thiz)) {
-                return ((GlobalObject)Context.getGlobalTrusted()).wrapAsObject(thiz);
+                return Context.getGlobal().wrapAsObject(thiz);
             }
         }
 
--- a/src/jdk/nashorn/internal/runtime/ScriptObject.java	Thu Mar 20 16:26:54 2014 +0100
+++ b/src/jdk/nashorn/internal/runtime/ScriptObject.java	Fri Mar 21 17:52:03 2014 +0100
@@ -50,6 +50,7 @@
 import java.lang.invoke.MethodHandle;
 import java.lang.invoke.MethodHandles;
 import java.lang.invoke.MethodType;
+import java.lang.invoke.SwitchPoint;
 import java.util.AbstractMap;
 import java.util.ArrayList;
 import java.util.Arrays;
@@ -61,7 +62,6 @@
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
-
 import jdk.internal.dynalink.CallSiteDescriptor;
 import jdk.internal.dynalink.linker.GuardedInvocation;
 import jdk.internal.dynalink.linker.LinkRequest;
@@ -72,6 +72,7 @@
 import jdk.nashorn.internal.lookup.Lookup;
 import jdk.nashorn.internal.objects.AccessorPropertyDescriptor;
 import jdk.nashorn.internal.objects.DataPropertyDescriptor;
+import jdk.nashorn.internal.objects.Global;
 import jdk.nashorn.internal.objects.NativeArray;
 import jdk.nashorn.internal.runtime.arrays.ArrayData;
 import jdk.nashorn.internal.runtime.arrays.ArrayIndex;
@@ -96,7 +97,7 @@
  * </ul>
  */
 
-public abstract class ScriptObject extends PropertyListenerManager implements PropertyAccess {
+public abstract class ScriptObject implements PropertyAccess {
     /** __proto__ special property name */
     public static final String PROTO_PROPERTY_NAME   = "__proto__";
 
@@ -115,11 +116,8 @@
     /** Per ScriptObject flag - is this an arguments object? */
     public static final int IS_ARGUMENTS   = 1 << 2;
 
-    /** Is this a prototype PropertyMap? */
-    public static final int IS_PROTOTYPE   = 1 << 3;
-
     /** Is length property not-writable? */
-    public static final int IS_LENGTH_NOT_WRITABLE = 1 << 4;
+    public static final int IS_LENGTH_NOT_WRITABLE = 1 << 3;
 
     /**
      * Spill growth rate - by how many elements does {@link ScriptObject#primitiveSpill} and
@@ -153,7 +151,8 @@
 
     static final MethodHandle GETPROTO           = findOwnMH_V("getProto", ScriptObject.class);
     static final MethodHandle SETPROTOCHECK      = findOwnMH_V("setProtoCheck", void.class, Object.class);
-    static final MethodHandle MEGAMORPHIC_GET    = findOwnMH_V("megamorphicGet", Object.class, String.class, boolean.class);
+    static final MethodHandle MEGAMORPHIC_GET    = findOwnMH_V("megamorphicGet", Object.class, String.class, boolean.class, boolean.class);
+    static final MethodHandle GLOBALFILTER       = findOwnMH_S("globalFilter", Object.class, Object.class);
 
     private static final MethodHandle TRUNCATINGFILTER   = findOwnMH_S("truncatingFilter", Object[].class, int.class, Object[].class);
     private static final MethodHandle KNOWNFUNCPROPGUARD = findOwnMH_S("knownFunctionPropertyGuard", boolean.class, Object.class, PropertyMap.class, MethodHandle.class, Object.class, ScriptFunction.class);
@@ -182,7 +181,7 @@
     public static final Call GET_PROTO_DEPTH    = virtualCallNoLookup(ScriptObject.class, "getProto", ScriptObject.class, int.class);
 
     /** Method handle for setting the proto of a ScriptObject */
-    public static final Call SET_PROTO          = virtualCallNoLookup(ScriptObject.class, "setProto", void.class, ScriptObject.class);
+    public static final Call SET_PROTO          = virtualCallNoLookup(ScriptObject.class, "setInitialProto", void.class, ScriptObject.class);
 
     /** Method handle for setting the proto of a ScriptObject after checking argument */
     public static final Call SET_PROTO_CHECK    = virtualCallNoLookup(ScriptObject.class, "setProtoCheck", void.class, Object.class);
@@ -221,7 +220,6 @@
         if (Context.DEBUG) {
             ScriptObject.count++;
         }
-
         this.arrayData = ArrayData.EMPTY_ARRAY;
         this.setMap(map == null ? PropertyMap.newMap() : map);
     }
@@ -238,9 +236,6 @@
     protected ScriptObject(final ScriptObject proto, final PropertyMap map) {
         this(map);
         this.proto = proto;
-        if (proto != null) {
-            proto.setIsPrototype();
-        }
     }
 
     /**
@@ -298,8 +293,9 @@
             final Property oldProp = newMap.findProperty(key);
             if (oldProp == null) {
                 if (property instanceof UserAccessorProperty) {
+                    // Note: we copy accessor functions to this object which is semantically different from binding.
                     final UserAccessorProperty prop = this.newUserAccessors(key, property.getFlags(), property.getGetterFunction(source), property.getSetterFunction(source));
-                    newMap = newMap.addProperty(prop);
+                    newMap = newMap.addPropertyNoHistory(prop);
                 } else {
                     newMap = newMap.addPropertyBind((AccessorProperty)property, source);
                 }
@@ -395,18 +391,18 @@
       * @return property descriptor
       */
     public final PropertyDescriptor toPropertyDescriptor() {
-        final GlobalObject global = (GlobalObject) Context.getGlobalTrusted();
+        final Global global = Context.getGlobal();
 
         final PropertyDescriptor desc;
         if (isDataDescriptor()) {
             if (has(SET) || has(GET)) {
-                throw typeError((ScriptObject)global, "inconsistent.property.descriptor");
+                throw typeError(global, "inconsistent.property.descriptor");
             }
 
             desc = global.newDataDescriptor(UNDEFINED, false, false, false);
         } else if (isAccessorDescriptor()) {
             if (has(VALUE) || has(WRITABLE)) {
-                throw typeError((ScriptObject)global, "inconsistent.property.descriptor");
+                throw typeError(global, "inconsistent.property.descriptor");
             }
 
             desc = global.newAccessorDescriptor(UNDEFINED, UNDEFINED, false, false);
@@ -425,7 +421,7 @@
      *
      * @return property descriptor
      */
-    public static PropertyDescriptor toPropertyDescriptor(final ScriptObject global, final Object obj) {
+    public static PropertyDescriptor toPropertyDescriptor(final Global global, final Object obj) {
         if (obj instanceof ScriptObject) {
             return ((ScriptObject)obj).toPropertyDescriptor();
         }
@@ -444,7 +440,7 @@
     public Object getOwnPropertyDescriptor(final String key) {
         final Property property = getMap().findProperty(key);
 
-        final GlobalObject global = (GlobalObject)Context.getGlobalTrusted();
+        final Global global = Context.getGlobal();
 
         if (property != null) {
             final ScriptFunction get   = property.getGetterFunction(this);
@@ -509,7 +505,7 @@
      * @return true if property was successfully defined
      */
     public boolean defineOwnProperty(final String key, final Object propertyDesc, final boolean reject) {
-        final ScriptObject       global  = Context.getGlobalTrusted();
+        final Global             global  = Context.getGlobal();
         final PropertyDescriptor desc    = toPropertyDescriptor(global, propertyDesc);
         final Object             current = getOwnPropertyDescriptor(key);
         final String             name    = JSType.toString(key);
@@ -716,7 +712,7 @@
         final int propFlags = Property.toFlags(pdesc);
 
         if (pdesc.type() == PropertyDescriptor.GENERIC) {
-            final GlobalObject global = (GlobalObject) Context.getGlobalTrusted();
+            final Global global = Context.getGlobal();
             final PropertyDescriptor dDesc = global.newDataDescriptor(UNDEFINED, false, false, false);
 
             dDesc.fillFrom((ScriptObject)pdesc);
@@ -977,8 +973,6 @@
             newProperty = newUserAccessors(oldProperty.getKey(), propertyFlags, getter, setter);
         }
 
-        notifyPropertyModified(this, oldProperty, newProperty);
-
         return modifyOwnProperty(oldProperty, newProperty);
     }
 
@@ -1089,17 +1083,6 @@
     }
 
     /**
-      * Get the object value of a property
-      *
-      * @param find {@link FindProperty} lookup result
-      *
-      * @return the value of the property
-      */
-    protected static Object getObjectValue(final FindProperty find) {
-        return find.getObjectValue();
-    }
-
-    /**
      * Return methodHandle of value function for call.
      *
      * @param find      data from find property.
@@ -1109,7 +1092,7 @@
      * @return value of property as a MethodHandle or null.
      */
     protected MethodHandle getCallMethodHandle(final FindProperty find, final MethodType type, final String bindName) {
-        return getCallMethodHandle(getObjectValue(find), type, bindName);
+        return getCallMethodHandle(find.getObjectValue(), type, bindName);
     }
 
     /**
@@ -1133,7 +1116,7 @@
      * @return Value of property.
      */
     public final Object getWithProperty(final Property property) {
-        return getObjectValue(new FindProperty(this, this, property));
+        return new FindProperty(this, this, property).getObjectValue();
     }
 
     /**
@@ -1238,26 +1221,30 @@
      */
     public final void setProto(final ScriptObject newProto) {
         final ScriptObject oldProto = proto;
-        map = map.changeProto(oldProto, newProto);
-
-        if (newProto != null) {
-            newProto.setIsPrototype();
+
+        if (oldProto != newProto) {
+            proto = newProto;
+
+            // Let current listeners know that the protototype has changed and set our map
+            final PropertyListeners listeners = getMap().getListeners();
+            if (listeners != null) {
+                listeners.protoChanged();
+            }
+            // Replace our current allocator map with one that is associated with the new prototype.
+            setMap(getMap().changeProto(newProto));
         }
-
-        proto = newProto;
-
-        if (isPrototype()) {
-            // tell listeners that my __proto__ has been changed
-            notifyProtoChanged(this, oldProto, newProto);
-
-            if (oldProto != null) {
-                oldProto.removePropertyListener(this);
-            }
-
-            if (newProto != null) {
-                newProto.addPropertyListener(this);
-            }
-        }
+    }
+
+    /**
+     * Set the initial __proto__ of this object. This should be used instead of
+     * {@link #setProto} if it is known that the current property map will not be
+     * used on a new object with any other parent property map, so we can pass over
+     * property map invalidation/evolution.
+     *
+     * @param initialProto the initial __proto__ to set.
+     */
+    public void setInitialProto(final ScriptObject initialProto) {
+        this.proto = initialProto;
     }
 
     /**
@@ -1280,7 +1267,7 @@
             }
             setProto((ScriptObject)newProto);
         } else {
-            final ScriptObject global = Context.getGlobalTrusted();
+            final Global global = Context.getGlobal();
             final Object  newProtoObject = JSType.toScriptObject(global, newProto);
 
             if (newProtoObject instanceof ScriptObject) {
@@ -1370,11 +1357,11 @@
      * @return the default value
      */
     public Object getDefaultValue(final Class<?> typeHint) {
-        // We delegate to GlobalObject, as the implementation uses dynamic call sites to invoke object's "toString" and
+        // We delegate to Global, as the implementation uses dynamic call sites to invoke object's "toString" and
         // "valueOf" methods, and in order to avoid those call sites from becoming megamorphic when multiple contexts
         // are being executed in a long-running program, we move the code and their associated dynamic call sites
         // (Global.TO_STRING and Global.VALUE_OF) into per-context code.
-        return ((GlobalObject)Context.getGlobalTrusted()).getDefaultValue(this, typeHint);
+        return Context.getGlobal().getDefaultValue(this, typeHint);
     }
 
     /**
@@ -1450,25 +1437,6 @@
     }
 
     /**
-     * Check if this object is a prototype
-     *
-     * @return {@code true} if is prototype
-     */
-    public final boolean isPrototype() {
-        return (flags & IS_PROTOTYPE) != 0;
-    }
-
-    /**
-     * Flag this object as having a prototype.
-     */
-    public final void setIsPrototype() {
-        if (proto != null && !isPrototype()) {
-            proto.addPropertyListener(this);
-        }
-        flags |= IS_PROTOTYPE;
-    }
-
-    /**
      * Check if this object has non-writable length property
      *
      * @return {@code true} if 'length' property is non-writable
@@ -1883,7 +1851,7 @@
         final String  name = desc.getNameToken(CallSiteDescriptor.NAME_OPERAND);
 
         if (request.isCallSiteUnstable() || hasWithScope()) {
-            return findMegaMorphicGetMethod(desc, name, "getMethod".equals(operator));
+            return findMegaMorphicGetMethod(desc, name, "getMethod".equals(operator), isScope() && NashornCallSiteDescriptor.isScope(desc));
         }
 
         final FindProperty find = findProperty(name, true);
@@ -1921,60 +1889,48 @@
                 UnwarrantedOptimismException.INVALID_PROGRAM_POINT;
 
         mh = find.getGetter(returnType, programPoint);
-
-        //we never need a guard if noGuard is set
-        final boolean noGuard = OBJECT_FIELDS_ONLY && NashornCallSiteDescriptor.isFastScope(desc) && !property.canChangeType();
-        MethodHandle guard;
-        final Class<? extends Throwable> exception;
-        if (noGuard) {
-            guard     = null;
-            exception = null;
-        } else {
-            guard     = NashornGuards.getMapGuard(map, explicitInstanceOfCheck);
-            exception = explicitInstanceOfCheck ? null : ClassCastException.class;
-        }
-
-        assert noGuard == (guard == null);
+        // Get the appropriate guard for this callsite and property.
+        MethodHandle guard = NashornGuards.getGuard(this, property, desc, explicitInstanceOfCheck);
+        final ScriptObject owner = find.getOwner();
+        final Class<ClassCastException> exception = explicitInstanceOfCheck ? null : ClassCastException.class;
 
         if (mh == null) {
             mh = Lookup.emptyGetter(returnType);
-        } else {
-             assert mh.type().returnType().equals(returnType) : "returntype mismatch for getter " + mh.type().returnType() + " != " + returnType;
-
-             if (find.isSelf()) {
-                return new GuardedInvocation(mh, guard, null, exception);
-             }
-
-             if (!property.hasGetterFunction(find.getOwner())) {
-                 if (isScope()) {
-                     mh = addProtoFilter(mh, find.getProtoChainLength());
-                     guard = NashornGuards.getMapGuard(find.getOwner().getMap(), explicitInstanceOfCheck);
-                     guard = addProtoFilter(guard, find.getProtoChainLength());
-                 } else {
-                     mh = bindTo(mh, find.getOwner());
-                 }
-             }
-         }
+        } else if (find.isSelf()) {
+            return new GuardedInvocation(mh, guard, null, exception);
+         } else {
+            assert mh.type().returnType().equals(returnType) : "returntype mismatch for getter " + mh.type().returnType() + " != " + returnType;
+            if (!property.hasGetterFunction(owner)) {
+                // Add a filter that replaces the self object with the prototype owning the property.
+                mh = addProtoFilter(mh, find.getProtoChainLength());
+            }
+        }
 
         assert OBJECT_FIELDS_ONLY || guard != null : "we always need a map guard here";
 
         return new GuardedInvocation(
                 mh,
                 guard,
-                getMap().getProtoGetSwitchPoint(proto, name),
+                getProtoSwitchPoint(name, owner),
                 exception);
     }
 
-    private static GuardedInvocation findMegaMorphicGetMethod(final CallSiteDescriptor desc, final String name, final boolean isMethod) {
-        ObjectClassGenerator.LOG.warning("Megamorphic getter: " + desc + " " + name + " " +isMethod);
-        return new GuardedInvocation(MH.insertArguments(MEGAMORPHIC_GET, 1, name, isMethod), getScriptObjectGuard(desc.getMethodType(), true), null, null);
+    private static GuardedInvocation findMegaMorphicGetMethod(final CallSiteDescriptor desc, final String name,
+                                                              final boolean isMethod, final boolean isScope) {
+    ObjectClassGenerator.LOG.warning("Megamorphic getter: " + desc + " " + name + " " +isMethod);
+        final MethodHandle invoker = MH.insertArguments(MEGAMORPHIC_GET, 1, name, isMethod, isScope);
+        final MethodHandle guard = getScriptObjectGuard(desc.getMethodType(), true);
+        return new GuardedInvocation(invoker, guard);
     }
 
     @SuppressWarnings("unused")
-    private Object megamorphicGet(final String key, final boolean isMethod) {
+    private Object megamorphicGet(final String key, final boolean isMethod, final boolean isScope) {
         final FindProperty find = findProperty(key, true);
         if (find != null) {
-            return getObjectValue(find);
+            return find.getObjectValue();
+        }
+        if (isScope) {
+            throw referenceError("not.defined", key);
         }
 
         return isMethod ? getNoSuchMethod(key, INVALID_PROGRAM_POINT) : invokeNoSuchProperty(key, INVALID_PROGRAM_POINT);
@@ -2034,6 +1990,28 @@
     }
 
     /**
+     * Get a switch point for a property with the given {@code name} that will be invalidated when
+     * the property definition is changed in this object's prototype chain. Returns {@code null} if
+     * the property is defined in this object itself.
+     *
+     * @param name the property name
+     * @param owner the property owner, null if property is not defined
+     * @return a SwitchPoint or null
+     */
+    public final SwitchPoint getProtoSwitchPoint(final String name, final ScriptObject owner) {
+        if (owner == this || getProto() == null) {
+            return null;
+        }
+
+        for (ScriptObject obj = this; obj != owner && obj.getProto() != null; obj = obj.getProto()) {
+            ScriptObject parent = obj.getProto();
+            parent.getMap().addListener(name, obj.getMap());
+        }
+
+        return getMap().getSwitchPoint(name);
+    }
+
+    /**
      * Find the appropriate SET method for an invoke dynamic call.
      *
      * @param desc    the call site descriptor
@@ -2096,11 +2074,10 @@
            throw typeError(strictErrorMessage, name, ScriptRuntime.safeToString(this));
         }
         assert canBeFastScope || !NashornCallSiteDescriptor.isFastScope(desc);
-        final PropertyMap myMap = getMap();
         return new GuardedInvocation(
                 Lookup.EMPTY_SETTER,
-                NashornGuards.getMapGuard(myMap, explicitInstanceOfCheck),
-                myMap.getProtoGetSwitchPoint(proto, name),
+                NashornGuards.getMapGuard(getMap(), explicitInstanceOfCheck),
+                getProtoSwitchPoint(name, null),
                 explicitInstanceOfCheck ? null : ClassCastException.class);
     }
 
@@ -2120,10 +2097,19 @@
     private GuardedInvocation findMegaMorphicSetMethod(final CallSiteDescriptor desc, final String name) {
         final MethodType        type = desc.getMethodType().insertParameterTypes(1, Object.class);
         //never bother with ClassCastExceptionGuard for megamorphic callsites
-        final GuardedInvocation inv  = findSetIndexMethod(getClass(), false, type, NashornCallSiteDescriptor.isStrict(desc));
+        final GuardedInvocation inv = findSetIndexMethod(getClass(), false, type, NashornCallSiteDescriptor.isStrict(desc));
         return inv.replaceMethods(MH.insertArguments(inv.getInvocation(), 1, name), inv.getGuard());
     }
 
+    @SuppressWarnings("unused")
+    private static Object globalFilter(final Object object) {
+        ScriptObject sobj = (ScriptObject) object;
+        while (sobj != null && !(sobj instanceof Global)) {
+            sobj = sobj.getProto();
+        }
+        return sobj;
+    }
+
     /**
      * Lookup function for the set index method, available for subclasses as well, e.g. {@link NativeArray}
      * provides special quick accessor linkage for continuous arrays that are represented as Java arrays
@@ -2173,7 +2159,7 @@
 
         final boolean explicitInstanceOfCheck = explicitInstanceOfCheck(desc, request);
 
-        final Object value = getObjectValue(find);
+        final Object value = find.getObjectValue();
         if (!(value instanceof ScriptFunction)) {
             return createEmptyGetter(desc, explicitInstanceOfCheck, name);
         }
@@ -2206,7 +2192,7 @@
         final boolean      scopeAccess = isScope() && NashornCallSiteDescriptor.isScope(desc);
 
         if (find != null) {
-            final Object   value        = getObjectValue(find);
+            final Object   value        = find.getObjectValue();
             ScriptFunction func         = null;
             MethodHandle   methodHandle = null;
 
@@ -2227,7 +2213,7 @@
                                 find.getGetter(Object.class, INVALID_PROGRAM_POINT),
                                 find.getOwner(),
                                 func),
-                        find.isInherited() ? getMap().getProtoGetSwitchPoint(proto, NO_SUCH_PROPERTY_NAME) : null,
+                        getProtoSwitchPoint(NO_SUCH_PROPERTY_NAME, find.getOwner()),
                         //TODO this doesn't need a ClassCastException as guard always checks script object
                         null);
             }
@@ -2252,7 +2238,7 @@
         Object ret = UNDEFINED;
 
         if (find != null) {
-            final Object func = getObjectValue(find);
+            final Object func = find.getObjectValue();
 
             if (func instanceof ScriptFunction) {
                 ret = ScriptRuntime.apply((ScriptFunction)func, this, name);
@@ -2279,7 +2265,7 @@
             return invokeNoSuchProperty(name, programPoint);
         }
 
-        final Object value = getObjectValue(find);
+        final Object value = find.getObjectValue();
         if (!(value instanceof ScriptFunction)) {
             return UNDEFINED;
         }
@@ -2292,14 +2278,9 @@
             throw new UnwarrantedOptimismException(UNDEFINED, NashornCallSiteDescriptor.getProgramPoint(desc), Type.OBJECT);
         }
 
-        return new GuardedInvocation(
-                Lookup.emptyGetter(
-                        desc.getMethodType().returnType()),
-                        NashornGuards.getMapGuard(getMap(), explicitInstanceOfCheck),
-                        getMap().getProtoGetSwitchPoint(proto, name),
-                        explicitInstanceOfCheck ?
-                                null :
-                                ClassCastException.class);
+        return new GuardedInvocation(Lookup.emptyGetter(desc.getMethodType().returnType()),
+                NashornGuards.getMapGuard(getMap(), explicitInstanceOfCheck), getProtoSwitchPoint(name, null),
+                explicitInstanceOfCheck ? null : ClassCastException.class);
     }
 
     private abstract static class ScriptObjectIterator <T extends Object> implements Iterator<T> {
@@ -2383,14 +2364,12 @@
             property = hasInitialValue ?
                 new AccessorProperty(key, propertyFlags, fieldCount, this, value) :
                 new AccessorProperty(key, propertyFlags, getClass(), fieldCount);
-            notifyPropertyAdded(this, property);
             property = addOwnProperty(property);
         } else {
             final int spillCount = propertyMap.getSpillLength();
             property = hasInitialValue ?
                 new SpillProperty(key, propertyFlags, spillCount, this, value) :
                 new SpillProperty(key, propertyFlags, spillCount);
-            notifyPropertyAdded(this, property);
             property = addOwnProperty(property);
             ensureSpillSize(property.getSlot());
         }
@@ -2821,7 +2800,7 @@
                     final FindProperty find = object.findProperty(key, false, false, this);
 
                     if (find != null) {
-                        return getObjectValue(find);
+                        return find.getObjectValue();
                     }
                 }
 
@@ -2839,7 +2818,7 @@
             final FindProperty find = findProperty(key, true);
 
             if (find != null) {
-                return getObjectValue(find);
+                return find.getObjectValue();
             }
         }
 
@@ -3036,10 +3015,18 @@
                 throw typeError("object.non.extensible", key, ScriptRuntime.safeToString(this));
             }
         } else {
+            ScriptObject sobj = this;
+            // undefined scope properties are set in the global object.
+            if (isScope()) {
+                while (sobj != null && !(sobj instanceof Global)) {
+                    sobj = sobj.getProto();
+                }
+                assert sobj != null : "no parent global object in scope";
+            }
             //this will unbox any Number object to its primitive type in case the
             //property supporst primitive types, so it doesn't matter that it comes
             //in as an Object.
-            addSpillProperty(key, 0, value, true);
+            sobj.addSpillProperty(key, 0, value, true);
         }
     }
 
@@ -3481,7 +3468,6 @@
         }
 
         final Property prop = find.getProperty();
-        notifyPropertyDeleted(this, prop);
         deleteOwnProperty(prop);
 
         return true;
@@ -3527,11 +3513,12 @@
     }
 
     private static MethodHandle findOwnMH_V(final Class<? extends ScriptObject> clazz, final String name, final Class<?> rtype, final Class<?>... types) {
+        // TODO: figure out how can it work for NativeArray$Prototype etc.
         return MH.findVirtual(MethodHandles.lookup(), ScriptObject.class, name, MH.type(rtype, types));
     }
 
     private static MethodHandle findOwnMH_V(final String name, final Class<?> rtype, final Class<?>... types) {
-        return MH.findVirtual(MethodHandles.lookup(), ScriptObject.class, name, MH.type(rtype, types));
+        return findOwnMH_V(ScriptObject.class, name, rtype, types);
     }
 
     private static MethodHandle findOwnMH_S(final String name, final Class<?> rtype, final Class<?>... types) {
--- a/src/jdk/nashorn/internal/runtime/ScriptRuntime.java	Thu Mar 20 16:26:54 2014 +0100
+++ b/src/jdk/nashorn/internal/runtime/ScriptRuntime.java	Fri Mar 21 17:52:03 2014 +0100
@@ -473,7 +473,7 @@
      * @return {@link WithObject} that is the new scope
      */
     public static ScriptObject openWith(final ScriptObject scope, final Object expression) {
-        final ScriptObject global = Context.getGlobalTrusted();
+        final Global global = Context.getGlobal();
         if (expression == UNDEFINED) {
             throw typeError(global, "cant.apply.with.to.undefined");
         } else if (expression == null) {
--- a/src/jdk/nashorn/internal/runtime/SetMethodCreator.java	Thu Mar 20 16:26:54 2014 +0100
+++ b/src/jdk/nashorn/internal/runtime/SetMethodCreator.java	Fri Mar 21 17:52:03 2014 +0100
@@ -25,7 +25,6 @@
 
 package jdk.nashorn.internal.runtime;
 
-import static jdk.nashorn.internal.codegen.ObjectClassGenerator.OBJECT_FIELDS_ONLY;
 import static jdk.nashorn.internal.lookup.Lookup.MH;
 import static jdk.nashorn.internal.runtime.ECMAErrors.referenceError;
 import static jdk.nashorn.internal.runtime.JSType.getAccessorTypeIndex;
@@ -84,7 +83,7 @@
     }
 
     /**
-     * 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.
      *
      */
@@ -111,23 +110,8 @@
             // getGuard() and getException() either both return null, or neither does. The reason for that is that now
             // getGuard returns a map guard that casts its argument to ScriptObject, and if that fails, we need to
             // relink on ClassCastException.
-            return new GuardedInvocation(methodHandle, getGuard(), null, getException());
-        }
-
-        private Class<ClassCastException> getException() {
-            return needsNoGuard() ? null : ClassCastException.class;
-        }
-
-        private MethodHandle getGuard() {
-            return needsNoGuard() ? null : NashornGuards.getMapGuard(getMap(), explicitInstanceOfCheck);
-        }
-
-        private boolean needsNoGuard() {
-            return NashornCallSiteDescriptor.isFastScope(desc) && isPropertyTypeStable();
-        }
-
-        private boolean isPropertyTypeStable() {
-            return OBJECT_FIELDS_ONLY;
+            return new GuardedInvocation(methodHandle, NashornGuards.getGuard(sobj, property, desc, explicitInstanceOfCheck),
+                    null, explicitInstanceOfCheck ? null : ClassCastException.class);
         }
     }
 
@@ -162,10 +146,7 @@
 
         final MethodHandle boundHandle;
         if (!property.hasSetterFunction(find.getOwner()) && find.isInherited()) {
-            // Bind or add prototype filter depending on whether this is a scope object.
-            boundHandle = sobj.isScope() ?
-                    ScriptObject.addProtoFilter(methodHandle, find.getProtoChainLength()):
-                    ScriptObject.bindTo(methodHandle, find.getOwner());
+            boundHandle = ScriptObject.addProtoFilter(methodHandle, find.getProtoChainLength());
         } else {
             boundHandle = methodHandle;
         }
@@ -173,13 +154,16 @@
     }
 
     private SetMethod createGlobalPropertySetter() {
-        final ScriptObject global = Context.getGlobalTrusted();
-        return new SetMethod(ScriptObject.bindTo(global.addSpill(type, getName()), global), null);
+        final ScriptObject global = Context.getGlobal();
+        return new SetMethod(MH.filterArguments(global.addSpill(type, 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;
     }
 
--- a/src/jdk/nashorn/internal/runtime/UserAccessorProperty.java	Thu Mar 20 16:26:54 2014 +0100
+++ b/src/jdk/nashorn/internal/runtime/UserAccessorProperty.java	Fri Mar 21 17:52:03 2014 +0100
@@ -26,16 +26,15 @@
 package jdk.nashorn.internal.runtime;
 
 import static jdk.nashorn.internal.codegen.CompilerConstants.staticCall;
+import static jdk.nashorn.internal.lookup.Lookup.MH;
 import static jdk.nashorn.internal.runtime.ECMAErrors.typeError;
-import static jdk.nashorn.internal.runtime.ScriptRuntime.UNDEFINED;
-import static jdk.nashorn.internal.lookup.Lookup.MH;
 import static jdk.nashorn.internal.runtime.JSType.CONVERT_OBJECT_OPTIMISTIC;
 import static jdk.nashorn.internal.runtime.JSType.getAccessorTypeIndex;
+import static jdk.nashorn.internal.runtime.ScriptRuntime.UNDEFINED;
 
 import java.lang.invoke.MethodHandle;
 import java.lang.invoke.MethodHandles;
 import java.util.concurrent.Callable;
-
 import jdk.nashorn.internal.codegen.CompilerConstants;
 import jdk.nashorn.internal.lookup.Lookup;
 import jdk.nashorn.internal.runtime.linker.Bootstrap;
@@ -89,7 +88,7 @@
 
     private static MethodHandle getINVOKE_UA_GETTER() {
 
-        return ((GlobalObject)Context.getGlobal()).getDynamicInvoker(INVOKE_UA_GETTER,
+        return Context.getGlobal().getDynamicInvoker(INVOKE_UA_GETTER,
                 new Callable<MethodHandle>() {
                     @Override
                     public MethodHandle call() {
@@ -103,7 +102,7 @@
     private static Object INVOKE_UA_SETTER = new Object();
 
     private static MethodHandle getINVOKE_UA_SETTER() {
-        return ((GlobalObject)Context.getGlobal()).getDynamicInvoker(INVOKE_UA_SETTER,
+        return Context.getGlobal().getDynamicInvoker(INVOKE_UA_SETTER,
                 new Callable<MethodHandle>() {
                     @Override
                     public MethodHandle call() {
--- a/src/jdk/nashorn/internal/runtime/WithObject.java	Thu Mar 20 16:26:54 2014 +0100
+++ b/src/jdk/nashorn/internal/runtime/WithObject.java	Fri Mar 21 17:52:03 2014 +0100
@@ -31,26 +31,23 @@
 import java.lang.invoke.MethodHandles;
 import java.lang.invoke.MethodType;
 import java.lang.invoke.SwitchPoint;
-
 import jdk.internal.dynalink.CallSiteDescriptor;
 import jdk.internal.dynalink.linker.GuardedInvocation;
 import jdk.internal.dynalink.linker.LinkRequest;
 import jdk.internal.dynalink.support.CallSiteDescriptorFactory;
 import jdk.nashorn.internal.runtime.linker.NashornCallSiteDescriptor;
+import jdk.nashorn.internal.runtime.linker.NashornGuards;
 
 /**
  * This class supports the handling of scope in a with body.
  *
  */
 public final class WithObject extends ScriptObject implements Scope {
-    private static final MethodHandle WITHEXPRESSIONGUARD    = findOwnMH("withExpressionGuard",  boolean.class, ScriptObject.class, PropertyMap.class, SwitchPoint.class);
-    private static final MethodHandle WITHEXPRESSIONFILTER   = findOwnMH("withFilterExpression", ScriptObject.class, ScriptObject.class);
-    private static final MethodHandle WITHSCOPEFILTER        = findOwnMH("withFilterScope",      ScriptObject.class, ScriptObject.class);
-    private static final MethodHandle BIND_TO_EXPRESSION_OBJ = findOwnMH("bindToExpression",     Object.class, Object.class, ScriptObject.class);
-    private static final MethodHandle BIND_TO_EXPRESSION_FN  = findOwnMH("bindToExpression",     Object.class, ScriptFunction.class, ScriptObject.class);
-
-    private static final MethodHandle CONSTANT_FALSE_TAKE_SCRIPT_OBJECT = MH.dropArguments(MH.constant(boolean.class, false), 0, ScriptObject.class);
-
+    private static final MethodHandle WITHEXPRESSIONGUARD    = findOwnMH("withExpressionGuard",  boolean.class, Object.class, PropertyMap.class, SwitchPoint.class);
+    private static final MethodHandle WITHEXPRESSIONFILTER   = findOwnMH("withFilterExpression", Object.class, Object.class);
+    private static final MethodHandle WITHSCOPEFILTER        = findOwnMH("withFilterScope",      Object.class, Object.class);
+    private static final MethodHandle BIND_TO_EXPRESSION_OBJ = findOwnMH("bindToExpression",     Object.class, Object.class, Object.class);
+    private static final MethodHandle BIND_TO_EXPRESSION_FN  = findOwnMH("bindToExpression",     Object.class, ScriptFunction.class, Object.class);
 
     /** With expression object. */
     private final ScriptObject expression;
@@ -90,6 +87,11 @@
 
     @Override
     public GuardedInvocation lookup(final CallSiteDescriptor desc, final LinkRequest request) {
+        if (request.isCallSiteUnstable()) {
+            // Fall back to megamorphic invocation which performs a complete lookup each time without further relinking.
+            return super.lookup(desc, request);
+        }
+
         // With scopes can never be observed outside of Nashorn code, so all call sites that can address it will of
         // necessity have a Nashorn descriptor - it is safe to cast.
         final NashornCallSiteDescriptor ndesc = (NashornCallSiteDescriptor)desc;
@@ -125,7 +127,7 @@
         }
 
         if (find != null) {
-            return fixScopeCallSite(scope.lookup(desc, request), name);
+            return fixScopeCallSite(scope.lookup(desc, request), name, find.getOwner());
         }
 
         // the property is not found - now check for
@@ -177,7 +179,7 @@
         link = scope.lookup(desc, request);
 
         if (link != null) {
-            return fixScopeCallSite(link, name);
+            return fixScopeCallSite(link, name, null);
         }
 
         return null;
@@ -260,24 +262,17 @@
                                                         Object.class).
                                                             changeParameterType(
                                                                     0,
-                                                                    ScriptObject.class)),
+                                                                    Object.class)),
                                         WITHEXPRESSIONFILTER)),
                          filterGuardReceiver(link, WITHEXPRESSIONFILTER));
      // No clever things for the guard -- it is still identically filtered.
 
     }
 
-    private GuardedInvocation fixScopeCallSite(final GuardedInvocation link, final String name) {
+    private GuardedInvocation fixScopeCallSite(final GuardedInvocation link, final String name, final ScriptObject owner) {
         final GuardedInvocation newLink = fixReceiverType(link, WITHSCOPEFILTER);
-        final MethodHandle expressionGuard = expressionGuard(name);
-        final MethodHandle filteredGuard = filterGuardReceiver(newLink, WITHSCOPEFILTER);
-        final MethodHandle newGuard;
-        if (filteredGuard == null) {
-            newGuard = expressionGuard;
-        } else {
-            newGuard = MH.guardWithTest(expressionGuard, filteredGuard, CONSTANT_FALSE_TAKE_SCRIPT_OBJECT);
-        }
-        return link.replaceMethods(filterReceiver(newLink.getInvocation(), WITHSCOPEFILTER), newGuard);
+        return link.replaceMethods(filterReceiver(newLink.getInvocation(), WITHSCOPEFILTER),
+                NashornGuards.combineGuards(expressionGuard(name, owner), filterGuardReceiver(newLink, WITHSCOPEFILTER)));
     }
 
     private static MethodHandle filterGuardReceiver(final GuardedInvocation link, final MethodHandle receiverFilter) {
@@ -296,7 +291,7 @@
 
     private static MethodHandle filterReceiver(final MethodHandle mh, final MethodHandle receiverFilter) {
         //With expression filter == receiverFilter, i.e. receiver is cast to withobject and its expression returned
-        return MH.filterArguments(mh, 0, receiverFilter);
+        return MH.filterArguments(mh, 0, receiverFilter.asType(receiverFilter.type().changeReturnType(mh.type().parameterType(0))));
     }
 
     /**
@@ -304,27 +299,27 @@
      * @param receiver WithObject wrapper.
      * @return The with expression.
      */
-    public static ScriptObject withFilterExpression(final ScriptObject receiver) {
+    public static Object withFilterExpression(final Object receiver) {
         return ((WithObject)receiver).expression;
     }
 
     @SuppressWarnings("unused")
-    private static Object bindToExpression(final Object fn, final ScriptObject receiver) {
+    private static Object bindToExpression(final Object fn, final Object receiver) {
         return fn instanceof ScriptFunction ? bindToExpression((ScriptFunction) fn, receiver) : fn;
     }
 
-    private static Object bindToExpression(final ScriptFunction fn, final ScriptObject receiver) {
+    private static Object bindToExpression(final ScriptFunction fn, final Object receiver) {
         return fn.makeBoundFunction(withFilterExpression(receiver), ScriptRuntime.EMPTY_ARRAY);
     }
 
-    private MethodHandle expressionGuard(final String name) {
+    private MethodHandle expressionGuard(final String name, final ScriptObject owner) {
         final PropertyMap map = expression.getMap();
-        final SwitchPoint sp = map.getProtoGetSwitchPoint(expression.getProto(), name);
+        final SwitchPoint sp = expression.getProtoSwitchPoint(name, owner);
         return MH.insertArguments(WITHEXPRESSIONGUARD, 1, map, sp);
     }
 
     @SuppressWarnings("unused")
-    private static boolean withExpressionGuard(final ScriptObject receiver, final PropertyMap map, final SwitchPoint sp) {
+    private static boolean withExpressionGuard(final Object receiver, final PropertyMap map, final SwitchPoint sp) {
         return ((WithObject)receiver).expression.getMap() == map && (sp == null || !sp.hasBeenInvalidated());
     }
 
@@ -333,7 +328,7 @@
      * @param receiver WithObject wrapper.
      * @return The with scope.
      */
-    public static ScriptObject withFilterScope(final ScriptObject receiver) {
+    public static Object withFilterScope(final Object receiver) {
         return ((WithObject)receiver).getProto();
     }
 
--- a/src/jdk/nashorn/internal/runtime/arrays/ArrayData.java	Thu Mar 20 16:26:54 2014 +0100
+++ b/src/jdk/nashorn/internal/runtime/arrays/ArrayData.java	Fri Mar 21 17:52:03 2014 +0100
@@ -26,17 +26,16 @@
 package jdk.nashorn.internal.runtime.arrays;
 
 import static jdk.nashorn.internal.codegen.CompilerConstants.staticCall;
+
 import java.lang.invoke.MethodHandle;
 import java.lang.invoke.MethodHandles;
-
+import java.nio.ByteBuffer;
 import jdk.internal.dynalink.CallSiteDescriptor;
 import jdk.internal.dynalink.linker.GuardedInvocation;
 import jdk.internal.dynalink.linker.LinkRequest;
-
-import java.nio.ByteBuffer;
 import jdk.nashorn.internal.codegen.CompilerConstants;
 import jdk.nashorn.internal.codegen.types.Type;
-import jdk.nashorn.internal.runtime.GlobalObject;
+import jdk.nashorn.internal.objects.Global;
 import jdk.nashorn.internal.runtime.JSType;
 import jdk.nashorn.internal.runtime.PropertyDescriptor;
 import jdk.nashorn.internal.runtime.UnwarrantedOptimismException;
@@ -510,7 +509,7 @@
      *
      * @return property descriptor for element
      */
-    public PropertyDescriptor getDescriptor(final GlobalObject global, final int index) {
+    public PropertyDescriptor getDescriptor(final Global global, final int index) {
         return global.newDataDescriptor(getObject(index), true, true, true);
     }
 
--- a/src/jdk/nashorn/internal/runtime/arrays/ByteBufferArrayData.java	Thu Mar 20 16:26:54 2014 +0100
+++ b/src/jdk/nashorn/internal/runtime/arrays/ByteBufferArrayData.java	Fri Mar 21 17:52:03 2014 +0100
@@ -27,7 +27,7 @@
 import static jdk.nashorn.internal.runtime.ECMAErrors.typeError;
 
 import java.nio.ByteBuffer;
-import jdk.nashorn.internal.runtime.GlobalObject;
+import jdk.nashorn.internal.objects.Global;
 import jdk.nashorn.internal.runtime.PropertyDescriptor;
 import jdk.nashorn.internal.runtime.ScriptRuntime;
 
@@ -61,7 +61,7 @@
      * @return property descriptor for element
      */
     @Override
-    public PropertyDescriptor getDescriptor(final GlobalObject global, final int index) {
+    public PropertyDescriptor getDescriptor(final Global global, final int index) {
         // make the index properties not configurable
         return global.newDataDescriptor(getObject(index), false, true, true);
     }
--- a/src/jdk/nashorn/internal/runtime/arrays/FrozenArrayFilter.java	Thu Mar 20 16:26:54 2014 +0100
+++ b/src/jdk/nashorn/internal/runtime/arrays/FrozenArrayFilter.java	Fri Mar 21 17:52:03 2014 +0100
@@ -25,9 +25,9 @@
 
 package jdk.nashorn.internal.runtime.arrays;
 
+import jdk.nashorn.internal.objects.Global;
 import static jdk.nashorn.internal.runtime.ECMAErrors.typeError;
 
-import jdk.nashorn.internal.runtime.GlobalObject;
 import jdk.nashorn.internal.runtime.PropertyDescriptor;
 
 /**
@@ -44,7 +44,7 @@
     }
 
     @Override
-    public PropertyDescriptor getDescriptor(final GlobalObject global, final int index) {
+    public PropertyDescriptor getDescriptor(final Global global, final int index) {
         return global.newDataDescriptor(getObject(index), false, true, false);
     }
 
--- a/src/jdk/nashorn/internal/runtime/arrays/SealedArrayFilter.java	Thu Mar 20 16:26:54 2014 +0100
+++ b/src/jdk/nashorn/internal/runtime/arrays/SealedArrayFilter.java	Fri Mar 21 17:52:03 2014 +0100
@@ -25,9 +25,9 @@
 
 package jdk.nashorn.internal.runtime.arrays;
 
+import jdk.nashorn.internal.objects.Global;
 import static jdk.nashorn.internal.runtime.ECMAErrors.typeError;
 
-import jdk.nashorn.internal.runtime.GlobalObject;
 import jdk.nashorn.internal.runtime.PropertyDescriptor;
 
 /**
@@ -62,7 +62,7 @@
     }
 
     @Override
-    public PropertyDescriptor getDescriptor(final GlobalObject global, final int index) {
+    public PropertyDescriptor getDescriptor(final Global global, final int index) {
         return global.newDataDescriptor(getObject(index), false, true, true);
     }
 }
--- a/src/jdk/nashorn/internal/runtime/linker/JavaAdapterBytecodeGenerator.java	Thu Mar 20 16:26:54 2014 +0100
+++ b/src/jdk/nashorn/internal/runtime/linker/JavaAdapterBytecodeGenerator.java	Fri Mar 21 17:52:03 2014 +0100
@@ -64,6 +64,7 @@
 import jdk.internal.org.objectweb.asm.Opcodes;
 import jdk.internal.org.objectweb.asm.Type;
 import jdk.internal.org.objectweb.asm.commons.InstructionAdapter;
+import jdk.nashorn.internal.objects.Global;
 import jdk.nashorn.internal.runtime.Context;
 import jdk.nashorn.internal.runtime.ScriptFunction;
 import jdk.nashorn.internal.runtime.ScriptObject;
@@ -134,6 +135,7 @@
     static final Type CONTEXT_TYPE       = Type.getType(Context.class);
     static final Type OBJECT_TYPE        = Type.getType(Object.class);
     static final Type SCRIPT_OBJECT_TYPE = Type.getType(ScriptObject.class);
+    static final Type GLOBAL_TYPE        = Type.getType(Global.class);
 
     static final String CONTEXT_TYPE_NAME = CONTEXT_TYPE.getInternalName();
     static final String OBJECT_TYPE_NAME  = OBJECT_TYPE.getInternalName();
@@ -143,8 +145,10 @@
     static final String GLOBAL_FIELD_NAME = "global";
 
     static final String SCRIPT_OBJECT_TYPE_DESCRIPTOR = SCRIPT_OBJECT_TYPE.getDescriptor();
+    static final String GLOBAL_TYPE_DESCRIPTOR = GLOBAL_TYPE.getDescriptor();
 
-    static final String SET_GLOBAL_METHOD_DESCRIPTOR = Type.getMethodDescriptor(Type.VOID_TYPE, SCRIPT_OBJECT_TYPE);
+
+    static final String SET_GLOBAL_METHOD_DESCRIPTOR = Type.getMethodDescriptor(Type.VOID_TYPE, GLOBAL_TYPE);
     static final String VOID_NOARG_METHOD_DESCRIPTOR = Type.getMethodDescriptor(Type.VOID_TYPE);
 
     private static final Type SCRIPT_FUNCTION_TYPE = Type.getType(ScriptFunction.class);
@@ -167,7 +171,7 @@
     private static final String UNSUPPORTED_OPERATION_TYPE_NAME = UNSUPPORTED_OPERATION_TYPE.getInternalName();
 
     private static final String METHOD_HANDLE_TYPE_DESCRIPTOR = METHOD_HANDLE_TYPE.getDescriptor();
-    private static final String GET_GLOBAL_METHOD_DESCRIPTOR = Type.getMethodDescriptor(SCRIPT_OBJECT_TYPE);
+    private static final String GET_GLOBAL_METHOD_DESCRIPTOR = Type.getMethodDescriptor(GLOBAL_TYPE);
     private static final String GET_CLASS_METHOD_DESCRIPTOR = Type.getMethodDescriptor(Type.getType(Class.class));
 
     // Package used when the adapter can't be defined in the adaptee's package (either because it's sealed, or because
@@ -259,7 +263,7 @@
     }
 
     private void generateGlobalFields() {
-        cw.visitField(ACC_PRIVATE | ACC_FINAL | (classOverride ? ACC_STATIC : 0), GLOBAL_FIELD_NAME, SCRIPT_OBJECT_TYPE_DESCRIPTOR, null, null).visitEnd();
+        cw.visitField(ACC_PRIVATE | ACC_FINAL | (classOverride ? ACC_STATIC : 0), GLOBAL_FIELD_NAME, GLOBAL_TYPE_DESCRIPTOR, null, null).visitEnd();
         usedFieldNames.add(GLOBAL_FIELD_NAME);
     }
 
@@ -363,7 +367,7 @@
         }
         // Assign "global = Context.getGlobal()"
         invokeGetGlobalWithNullCheck(mv);
-        mv.putstatic(generatedClassName, GLOBAL_FIELD_NAME, SCRIPT_OBJECT_TYPE_DESCRIPTOR);
+        mv.putstatic(generatedClassName, GLOBAL_FIELD_NAME, GLOBAL_TYPE_DESCRIPTOR);
 
         endInitMethod(mv);
     }
@@ -508,7 +512,7 @@
         // Assign "this.global = Context.getGlobal()"
         mv.visitVarInsn(ALOAD, 0);
         invokeGetGlobalWithNullCheck(mv);
-        mv.putfield(generatedClassName, GLOBAL_FIELD_NAME, SCRIPT_OBJECT_TYPE_DESCRIPTOR);
+        mv.putfield(generatedClassName, GLOBAL_FIELD_NAME, GLOBAL_TYPE_DESCRIPTOR);
 
         endInitMethod(mv);
     }
@@ -652,10 +656,10 @@
         // Load the creatingGlobal object
         if(classOverride) {
             // If class handle is defined, load the static defining global
-            mv.getstatic(generatedClassName, GLOBAL_FIELD_NAME, SCRIPT_OBJECT_TYPE_DESCRIPTOR);
+            mv.getstatic(generatedClassName, GLOBAL_FIELD_NAME, GLOBAL_TYPE_DESCRIPTOR);
         } else {
             mv.visitVarInsn(ALOAD, 0);
-            mv.getfield(generatedClassName, GLOBAL_FIELD_NAME, SCRIPT_OBJECT_TYPE_DESCRIPTOR);
+            mv.getfield(generatedClassName, GLOBAL_FIELD_NAME, GLOBAL_TYPE_DESCRIPTOR);
         }
         // stack: [creatingGlobal, handle]
         final Label setupGlobal = new Label();
@@ -674,7 +678,7 @@
         // stack: [creatingGlobal, creatingGlobal, handle]
 
         // Emit code for switching to the creating global
-        // ScriptObject currentGlobal = Context.getGlobal();
+        // Global currentGlobal = Context.getGlobal();
         invokeGetGlobal(mv);
         mv.dup();
 
@@ -744,7 +748,7 @@
         final Label methodEnd = new Label();
         mv.visitLabel(methodEnd);
 
-        mv.visitLocalVariable("currentGlobal", SCRIPT_OBJECT_TYPE_DESCRIPTOR, null, setupGlobal, methodEnd, currentGlobalVar);
+        mv.visitLocalVariable("currentGlobal", GLOBAL_TYPE_DESCRIPTOR, null, setupGlobal, methodEnd, currentGlobalVar);
         mv.visitLocalVariable("globalsDiffer", Type.INT_TYPE.getDescriptor(), null, setupGlobal, methodEnd, globalsDifferVar);
 
         if(throwableDeclared) {
--- a/src/jdk/nashorn/internal/runtime/linker/JavaAdapterFactory.java	Thu Mar 20 16:26:54 2014 +0100
+++ b/src/jdk/nashorn/internal/runtime/linker/JavaAdapterFactory.java	Fri Mar 21 17:52:03 2014 +0100
@@ -48,7 +48,6 @@
 import java.util.concurrent.ConcurrentHashMap;
 import jdk.internal.dynalink.beans.StaticClass;
 import jdk.internal.dynalink.support.LinkRequestImpl;
-import jdk.nashorn.internal.objects.NativeJava;
 import jdk.nashorn.internal.runtime.Context;
 import jdk.nashorn.internal.runtime.ECMAException;
 import jdk.nashorn.internal.runtime.ScriptFunction;
@@ -68,8 +67,8 @@
  * generate the adapter class itself; see its documentation for details about the generated class.
  * </p><p>
  * You normally don't use this class directly, but rather either create adapters from script using
- * {@link NativeJava#extend(Object, Object...)}, using the {@code new} operator on abstract classes and interfaces (see
- * {@link NativeJava#type(Object, Object)}), or implicitly when passing script functions to Java methods expecting SAM
+ * {@link jdk.nashorn.internal.objects.NativeJava#extend(Object, Object...)}, using the {@code new} operator on abstract classes and interfaces (see
+ * {@link jdk.nashorn.internal.objects.NativeJava#type(Object, Object)}), or implicitly when passing script functions to Java methods expecting SAM
  * types.
  * </p>
  */
@@ -337,6 +336,7 @@
     private static ProtectionDomain createMinimalPermissionDomain() {
         // Generated classes need to have at least the permission to access Nashorn runtime and runtime.linker packages.
         final Permissions permissions = new Permissions();
+        permissions.add(new RuntimePermission("accessClassInPackage.jdk.nashorn.internal.objects"));
         permissions.add(new RuntimePermission("accessClassInPackage.jdk.nashorn.internal.runtime"));
         permissions.add(new RuntimePermission("accessClassInPackage.jdk.nashorn.internal.runtime.linker"));
         return new ProtectionDomain(new CodeSource(null, (CodeSigner[])null), permissions);
--- a/src/jdk/nashorn/internal/runtime/linker/NashornGuards.java	Thu Mar 20 16:26:54 2014 +0100
+++ b/src/jdk/nashorn/internal/runtime/linker/NashornGuards.java	Fri Mar 21 17:52:03 2014 +0100
@@ -29,9 +29,12 @@
 
 import java.lang.invoke.MethodHandle;
 import java.lang.invoke.MethodHandles;
-
+import java.lang.ref.WeakReference;
 import jdk.internal.dynalink.CallSiteDescriptor;
 import jdk.internal.dynalink.linker.LinkRequest;
+import jdk.nashorn.internal.codegen.ObjectClassGenerator;
+import jdk.nashorn.internal.objects.Global;
+import jdk.nashorn.internal.runtime.Property;
 import jdk.nashorn.internal.runtime.PropertyMap;
 import jdk.nashorn.internal.runtime.ScriptFunction;
 import jdk.nashorn.internal.runtime.ScriptObject;
@@ -45,6 +48,8 @@
     private static final MethodHandle IS_MAP_SCRIPTOBJECT = findOwnMH("isMap", boolean.class, Object.class, PropertyMap.class);
     private static final MethodHandle IS_INSTANCEOF_2     = findOwnMH("isInstanceOf2", boolean.class, Object.class, Class.class, Class.class);
     private static final MethodHandle IS_SCRIPTOBJECT     = findOwnMH("isScriptObject", boolean.class, Object.class);
+    private static final MethodHandle SAME_OBJECT       = findOwnMH("sameObject", boolean.class, Object.class, WeakReference.class);
+    private static final MethodHandle IS_SCRIPTFUNCTION = findOwnMH("isScriptFunction", boolean.class, Object.class);
 
     private static final boolean CCE_ONLY = Options.getBooleanProperty("nashorn.cce");
 
@@ -100,6 +105,56 @@
     }
 
     /**
+     * Determine whether the given callsite needs a guard.
+     * @param property the property, or null
+     * @param desc the callsite descriptor
+     * @return true if a guard should be used for this callsite
+     */
+    static boolean needsGuard(final Property property, final CallSiteDescriptor desc) {
+        return property == null || property.isConfigurable()
+                || property.isBound() || !ObjectClassGenerator.OBJECT_FIELDS_ONLY
+                || !NashornCallSiteDescriptor.isFastScope(desc) || property.canChangeType();
+    }
+
+    /**
+     * Get the guard for a property access. This returns an identity guard for non-configurable global properties
+     * and a map guard for everything else.
+     *
+     * @param sobj the first object in the prototype chain
+     * @param property the property
+     * @param desc the callsite descriptor
+     * @param explicitInstanceOfCheck true if we should do an explicit script object instanceof check instead of just casting
+     * @return method handle for guard
+     */
+    public static MethodHandle getGuard(final ScriptObject sobj, final Property property, final CallSiteDescriptor desc, final boolean explicitInstanceOfCheck) {
+        if (!needsGuard(property, desc)) {
+            return null;
+        }
+        if (NashornCallSiteDescriptor.isScope(desc)) {
+            if (property != null && property.isBound() && !property.canChangeType()) {
+                // This is a declared top level variables in main script or eval, use identity guard.
+                return getIdentityGuard(sobj);
+            }
+            if (!(sobj instanceof Global) && (property == null || property.isConfigurable())) {
+                // Undeclared variables in nested evals need stronger guards
+                return combineGuards(getIdentityGuard(sobj), getMapGuard(sobj.getMap(), explicitInstanceOfCheck));
+            }
+        }
+        return getMapGuard(sobj.getMap(), explicitInstanceOfCheck);
+    }
+
+
+    /**
+     * Get a guard that checks referential identity of the current object.
+     *
+     * @param sobj the self object
+     * @return true if same self object instance
+     */
+    public static MethodHandle getIdentityGuard(final ScriptObject sobj) {
+        return MH.insertArguments(SAME_OBJECT, 1, new WeakReference<>(sobj));
+    }
+
+    /**
      * Get a guard that checks if in item is an instance of either of two classes.
      *
      * @param class1 the first class
@@ -110,6 +165,17 @@
         return MH.insertArguments(IS_INSTANCEOF_2, 1, class1, class2);
     }
 
+    /**
+     * Combine two method handles of type {@code (Object)boolean} using logical AND.
+     *
+     * @param guard1 the first guard
+     * @param guard2 the second guard, only invoked if guard1 returns true
+     * @return true if both guard1 and guard2 returned true
+     */
+    public static MethodHandle combineGuards(final MethodHandle guard1, final MethodHandle guard2) {
+        return MH.guardWithTest(guard1, guard2, MH.dropArguments(MH.constant(boolean.class, false), 0, Object.class));
+    }
+
     @SuppressWarnings("unused")
     private static boolean isScriptObject(final Object self) {
         return self instanceof ScriptObject;
@@ -132,6 +198,11 @@
 
 
     @SuppressWarnings("unused")
+    private static boolean sameObject(final Object self, final WeakReference<ScriptObject> ref) {
+        return self == ref.get();
+    }
+
+    @SuppressWarnings("unused")
     private static boolean isInstanceOf2(final Object self, final Class<?> class1, final Class<?> class2) {
         return class1.isInstance(self) || class2.isInstance(self);
     }
--- a/src/jdk/nashorn/internal/runtime/linker/NashornPrimitiveLinker.java	Thu Mar 20 16:26:54 2014 +0100
+++ b/src/jdk/nashorn/internal/runtime/linker/NashornPrimitiveLinker.java	Fri Mar 21 17:52:03 2014 +0100
@@ -37,9 +37,9 @@
 import jdk.internal.dynalink.linker.LinkerServices;
 import jdk.internal.dynalink.linker.TypeBasedGuardingDynamicLinker;
 import jdk.internal.dynalink.support.TypeUtilities;
+import jdk.nashorn.internal.objects.Global;
 import jdk.nashorn.internal.runtime.ConsString;
 import jdk.nashorn.internal.runtime.Context;
-import jdk.nashorn.internal.runtime.GlobalObject;
 
 /**
  * Internal linker for String, Boolean, and Number objects, only ever used by Nashorn engine and not exposed to other
@@ -62,7 +62,7 @@
         final LinkRequest request = origRequest.withoutRuntimeContext(); // Nashorn has no runtime context
 
         final Object self = request.getReceiver();
-        final GlobalObject global = (GlobalObject) Context.getGlobal();
+        final Global global = Context.getGlobal();
         final NashornCallSiteDescriptor desc = (NashornCallSiteDescriptor) request.getCallSiteDescriptor();
 
         return Bootstrap.asTypeSafeReturn(global.primitiveLookup(request, self), linkerServices, desc);
--- a/src/jdk/nashorn/internal/runtime/linker/PrimitiveLookup.java	Thu Mar 20 16:26:54 2014 +0100
+++ b/src/jdk/nashorn/internal/runtime/linker/PrimitiveLookup.java	Fri Mar 21 17:52:03 2014 +0100
@@ -35,6 +35,7 @@
 import jdk.internal.dynalink.support.CallSiteDescriptorFactory;
 import jdk.internal.dynalink.support.Guards;
 import jdk.nashorn.internal.lookup.Lookup;
+import jdk.nashorn.internal.runtime.FindProperty;
 import jdk.nashorn.internal.runtime.ScriptObject;
 
 /**
@@ -61,8 +62,9 @@
      * type {@code receiverClass}.
      */
     public static GuardedInvocation lookupPrimitive(final LinkRequest request, final Class<?> receiverClass,
-                                                    final ScriptObject wrappedReceiver, final MethodHandle wrapFilter) {
-        return lookupPrimitive(request, Guards.getInstanceOfGuard(receiverClass), wrappedReceiver, wrapFilter);
+                                                    final ScriptObject wrappedReceiver, final MethodHandle wrapFilter,
+                                                    final MethodHandle protoFilter) {
+        return lookupPrimitive(request, Guards.getInstanceOfGuard(receiverClass), wrappedReceiver, wrapFilter, protoFilter);
     }
 
     /**
@@ -79,7 +81,8 @@
      * type (that is implied by both {@code guard} and {@code wrappedReceiver}).
      */
     public static GuardedInvocation lookupPrimitive(final LinkRequest request, final MethodHandle guard,
-                                                    final ScriptObject wrappedReceiver, final MethodHandle wrapFilter) {
+                                                    final ScriptObject wrappedReceiver, final MethodHandle wrapFilter,
+                                                    final MethodHandle protoFilter) {
         final CallSiteDescriptor desc = request.getCallSiteDescriptor();
         final String operator = CallSiteDescriptorFactory.tokenizeOperators(desc).get(0);
         if ("setProp".equals(operator) || "setElem".equals(operator)) {
@@ -93,9 +96,23 @@
 
         if(desc.getNameTokenCount() > 2) {
             final String name = desc.getNameToken(CallSiteDescriptor.NAME_OPERAND);
-            if(wrappedReceiver.findProperty(name, true) == null) {
+            final FindProperty find = wrappedReceiver.findProperty(name, true);
+            if(find == null) {
                 // Give up early, give chance to BeanLinker and NashornBottomLinker to deal with it.
                 return null;
+            } else if (find.isInherited() && !find.getProperty().hasGetterFunction(find.getOwner())) {
+                // If property is found in the prototype object bind the method handle directly to
+                // the proto filter instead of going through wrapper instantiation below.
+                final ScriptObject proto = wrappedReceiver.getProto();
+                final GuardedInvocation link = proto.lookup(desc, request);
+
+                if (link != null) {
+                    final MethodHandle invocation = link.getInvocation();
+                    final MethodHandle adaptedInvocation = MH.asType(invocation, invocation.type().changeParameterType(0, Object.class));
+                    final MethodHandle method = MH.filterArguments(adaptedInvocation, 0, protoFilter);
+                    final MethodHandle protoGuard = MH.filterArguments(link.getGuard(), 0, protoFilter);
+                    return new GuardedInvocation(method, NashornGuards.combineGuards(guard, protoGuard));
+                }
             }
         }
         final GuardedInvocation link = wrappedReceiver.lookup(desc, request);
--- a/src/jdk/nashorn/internal/runtime/resources/Messages.properties	Thu Mar 20 16:26:54 2014 +0100
+++ b/src/jdk/nashorn/internal/runtime/resources/Messages.properties	Fri Mar 21 17:52:03 2014 +0100
@@ -80,6 +80,7 @@
 type.error.not.a.file={0} is not a File
 type.error.not.a.numeric.array={0} is not a numeric array
 type.error.not.a.bytebuffer={0} is not a java.nio.ByteBuffer
+type.error.not.an.arraybuffer.in.dataview=First arg to DataView constructor must be an ArrayBuffer
 
 # operations not permitted on undefined
 type.error.cant.call.undefined=Cannot call undefined
@@ -140,6 +141,8 @@
 type.error.unsupported.java.to.type=Unsupported Java.to target type {0}.
 type.error.constructor.requires.new=Constructor {0} requires 'new'.
 
+range.error.dataview.constructor.offset=Wrong offset or length in DataView constructor
+range.error.dataview.offset=Offset is outside the bounds of the DataView
 range.error.inappropriate.array.length=inappropriate array length: {0}
 range.error.inappropriate.array.buffer.length=inappropriate array buffer length: {0}
 range.error.invalid.fraction.digits=fractionDigits argument to {0} must be in [0, 20]
--- a/src/jdk/nashorn/internal/scripts/JO.java	Thu Mar 20 16:26:54 2014 +0100
+++ b/src/jdk/nashorn/internal/scripts/JO.java	Fri Mar 21 17:52:03 2014 +0100
@@ -34,7 +34,7 @@
  */
 public class JO extends ScriptObject {
 
-    private static final PropertyMap map$ = PropertyMap.newMap().setIsShared();
+    private static final PropertyMap map$ = PropertyMap.newMap();
 
     /**
      * Returns the initial property map to be used.
--- a/src/jdk/nashorn/tools/Shell.java	Thu Mar 20 16:26:54 2014 +0100
+++ b/src/jdk/nashorn/tools/Shell.java	Fri Mar 21 17:52:03 2014 +0100
@@ -44,6 +44,7 @@
 import jdk.nashorn.internal.ir.FunctionNode;
 import jdk.nashorn.internal.ir.debug.ASTWriter;
 import jdk.nashorn.internal.ir.debug.PrintVisitor;
+import jdk.nashorn.internal.objects.Global;
 import jdk.nashorn.internal.parser.Parser;
 import jdk.nashorn.internal.runtime.Context;
 import jdk.nashorn.internal.runtime.ErrorManager;
@@ -150,7 +151,7 @@
             return COMMANDLINE_ERROR;
         }
 
-        final ScriptObject global = context.createGlobal();
+        final Global global = context.createGlobal();
         final ScriptEnvironment env = context.getEnv();
         final List<String> files = env.getFiles();
         if (files.isEmpty()) {
@@ -234,8 +235,8 @@
      * @return error code
      * @throws IOException when any script file read results in I/O error
      */
-    private static int compileScripts(final Context context, final ScriptObject global, final List<String> files) throws IOException {
-        final ScriptObject oldGlobal = Context.getGlobal();
+    private static int compileScripts(final Context context, final Global global, final List<String> files) throws IOException {
+        final Global oldGlobal = Context.getGlobal();
         final boolean globalChanged = (oldGlobal != global);
         final ScriptEnvironment env = context.getEnv();
         try {
@@ -285,8 +286,8 @@
      * @return error code
      * @throws IOException when any script file read results in I/O error
      */
-    private int runScripts(final Context context, final ScriptObject global, final List<String> files) throws IOException {
-        final ScriptObject oldGlobal = Context.getGlobal();
+    private int runScripts(final Context context, final Global global, final List<String> files) throws IOException {
+        final Global oldGlobal = Context.getGlobal();
         final boolean globalChanged = (oldGlobal != global);
         try {
             if (globalChanged) {
@@ -343,8 +344,8 @@
      * @return error code
      * @throws IOException when any script file read results in I/O error
      */
-    private static int runFXScripts(final Context context, final ScriptObject global, final List<String> files) throws IOException {
-        final ScriptObject oldGlobal = Context.getGlobal();
+    private static int runFXScripts(final Context context, final Global global, final List<String> files) throws IOException {
+        final Global oldGlobal = Context.getGlobal();
         final boolean globalChanged = (oldGlobal != global);
         try {
             if (globalChanged) {
@@ -393,11 +394,11 @@
      * @return return code
      */
     @SuppressWarnings("resource")
-    private static int readEvalPrint(final Context context, final ScriptObject global) {
+    private static int readEvalPrint(final Context context, final Global global) {
         final String prompt = bundle.getString("shell.prompt");
         final BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
         final PrintWriter err = context.getErr();
-        final ScriptObject oldGlobal = Context.getGlobal();
+        final Global oldGlobal = Context.getGlobal();
         final boolean globalChanged = (oldGlobal != global);
         final ScriptEnvironment env = context.getEnv();
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/script/basic/JDK-8034055.js	Fri Mar 21 17:52:03 2014 +0100
@@ -0,0 +1,55 @@
+/*
+ * Copyright (c) 2010, 2014, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ * 
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ * 
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ * 
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ * 
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/**
+ * JDK-8034055: delete on global object not properly guarded
+ *
+ * @test
+ * @run
+ */
+
+
+var global = this;
+var x;
+
+function test(defineGlobals) {
+    if (defineGlobals) {
+        global.x = 1;
+        global.y = 2;
+    }
+    try {
+        print(x);
+        print(y);
+    } catch (e) {
+        print(e);
+    } finally {
+        print(delete global.x);
+        print(delete global.y);
+    }
+}
+
+// Repeatedly set and delete global variables
+test(true);
+test(false);
+test(true);
+test(false);
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/script/basic/JDK-8034055.js.EXPECTED	Fri Mar 21 17:52:03 2014 +0100
@@ -0,0 +1,16 @@
+1
+2
+false
+true
+1
+ReferenceError: "y" is not defined
+false
+true
+1
+2
+false
+true
+1
+ReferenceError: "y" is not defined
+false
+true
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/script/basic/dataview_endian.js	Fri Mar 21 17:52:03 2014 +0100
@@ -0,0 +1,70 @@
+/*
+ * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ * 
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ * 
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ * 
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ * 
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/**
+ * JDK-8015958: DataView constructor is not defined
+ *
+ * @test
+ * @run
+ */
+
+// set/get endianess checks
+
+var buffer = new ArrayBuffer(4);
+var dv = new DataView(buffer);
+
+// write (default) big endian, read big/little endian
+dv.setUint16(0, 0xABCD);
+Assert.assertEquals(dv.getUint16(0), 0xABCD);
+Assert.assertEquals(dv.getUint16(0, false), 0xABCD);
+Assert.assertEquals(dv.getUint16(0, true), 0xCDAB);
+
+// write little endian, read big/little endian
+dv.setUint16(0, 0xABCD, true);
+Assert.assertEquals(dv.getUint16(0), 0xCDAB);
+Assert.assertEquals(dv.getUint16(0, false), 0xCDAB);
+Assert.assertEquals(dv.getUint16(0, true), 0xABCD);
+
+// write explicit big endian, read big/little endian
+dv.setUint16(0, 0xABCD, false);
+Assert.assertEquals(dv.getUint16(0), 0xABCD);
+Assert.assertEquals(dv.getUint16(0, false), 0xABCD);
+Assert.assertEquals(dv.getUint16(0, true), 0xCDAB);
+
+// write (default) big endian, read big/little endian
+dv.setUint32(0, 0xABCDEF89);
+Assert.assertEquals(dv.getUint32(0), 0xABCDEF89);
+Assert.assertEquals(dv.getUint32(0, false), 0xABCDEF89);
+Assert.assertEquals(dv.getUint32(0, true), 0x89EFCDAB);
+
+// write little endian, read big/little endian
+dv.setUint32(0, 0xABCDEF89, true);
+Assert.assertEquals(dv.getUint32(0), 0x89EFCDAB);
+Assert.assertEquals(dv.getUint32(0, false), 0x89EFCDAB);
+Assert.assertEquals(dv.getUint32(0, true), 0xABCDEF89);
+
+// write explicit big endian, read big/little endian
+dv.setUint32(0, 0xABCDEF89, false);
+Assert.assertEquals(dv.getUint32(0), 0xABCDEF89);
+Assert.assertEquals(dv.getUint32(0, false), 0xABCDEF89);
+Assert.assertEquals(dv.getUint32(0, true), 0x89EFCDAB);
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/script/basic/dataview_getset.js	Fri Mar 21 17:52:03 2014 +0100
@@ -0,0 +1,93 @@
+/*
+ * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ * 
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ * 
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ * 
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ * 
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/**
+ * JDK-8015958: DataView constructor is not defined
+ *
+ * @test
+ * @run
+ */
+
+// checking get/set of values of various types
+// Also basic endianess check.
+
+var Float = Java.type("java.lang.Float");
+var Double = Java.type("java.lang.Double");
+
+var DOUBLE_MIN = Double.MIN_VALUE;
+var DOUBLE_MIN_NORMAL = Double.MIN_NORMAL;
+var FLOAT_MIN = Float.MIN_VALUE;
+var FLOAT_MIN_NORMAL = Float.MIN_NORMAL;
+
+var buffer = new ArrayBuffer(12);
+var dv = new DataView(buffer);
+
+dv.setInt8(1, 123);
+Assert.assertEquals(dv.getInt8(1), 123);
+dv.setInt8(1, 123, true);
+Assert.assertEquals(dv.getInt8(1, true), 123);
+
+dv.setUint8(1, 255);
+Assert.assertEquals(dv.getUint8(1), 255);
+dv.setUint8(1, 255, true);
+Assert.assertEquals(dv.getUint8(1, true), 255);
+
+dv.setInt16(1, 1234);
+Assert.assertEquals(dv.getInt16(1), 1234);
+dv.setInt16(1, 1234, true);
+Assert.assertEquals(dv.getInt16(1, true), 1234);
+
+dv.setUint16(1, 65535);
+Assert.assertEquals(dv.getUint16(1), 65535);
+dv.setUint16(1, 65535, true);
+Assert.assertEquals(dv.getUint16(1, true), 65535);
+
+dv.setInt32(1, 1234);
+Assert.assertEquals(dv.getInt32(1), 1234);
+dv.setInt32(1, 1234, true);
+Assert.assertEquals(dv.getInt32(1, true), 1234);
+
+dv.setUint32(1, 4294967295);
+Assert.assertEquals(dv.getUint32(1), 4294967295);
+dv.setUint32(1, 4294967295, true);
+Assert.assertEquals(dv.getUint32(1, true), 4294967295);
+
+dv.setFloat64(1, Math.PI);
+Assert.assertEquals(dv.getFloat64(1), Math.PI, DOUBLE_MIN);
+dv.setFloat64(1, Math.PI, true);
+Assert.assertEquals(dv.getFloat64(1, true), Math.PI, DOUBLE_MIN);
+
+dv.setFloat64(1, DOUBLE_MIN_NORMAL);
+Assert.assertEquals(dv.getFloat64(1), DOUBLE_MIN_NORMAL, DOUBLE_MIN);
+dv.setFloat64(1, DOUBLE_MIN_NORMAL, true);
+Assert.assertEquals(dv.getFloat64(1, true), DOUBLE_MIN_NORMAL, DOUBLE_MIN);
+
+dv.setFloat32(1, 1.414);
+Assert["assertEquals(float, float, float)"](dv.getFloat32(1), 1.414, FLOAT_MIN);
+dv.setFloat32(1, 1.414, true);
+Assert["assertEquals(float, float, float)"](dv.getFloat32(1, true), 1.414, FLOAT_MIN);
+
+dv.setFloat32(1, FLOAT_MIN_NORMAL);
+Assert["assertEquals(float, float, float)"](dv.getFloat32(1), FLOAT_MIN_NORMAL, FLOAT_MIN);
+dv.setFloat32(1, FLOAT_MIN_NORMAL, true);
+Assert["assertEquals(float, float, float)"](dv.getFloat32(1, true), FLOAT_MIN_NORMAL, FLOAT_MIN);
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/script/basic/dataview_new.js	Fri Mar 21 17:52:03 2014 +0100
@@ -0,0 +1,72 @@
+/*
+ * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ * 
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ * 
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ * 
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ * 
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/**
+ * JDK-8015958: DataView constructor is not defined
+ *
+ * @test
+ * @run
+ */
+
+// basic DataView constructor checks.
+
+// check ArrayBufferView property values of DataView instance
+function check(dv, buf, offset, length) {
+    if (dv.buffer !== buf) {
+        fail("DataView.buffer is wrong");
+    }
+
+    if (dv.byteOffset != offset) {
+        fail("DataView.byteOffset = " + dv.byteOffset + ", expected " + offset);
+    }
+
+    if (dv.byteLength != length) {
+        fail("DataView.byteLength = " + dv.byteLength + ", expected " + length);
+    }
+}
+
+var buffer = new ArrayBuffer(12);
+check(new DataView(buffer), buffer, 0, 12);
+check(new DataView(buffer, 2), buffer, 2, 10);
+check(new DataView(buffer, 4, 8), buffer, 4, 8);
+
+// make sure expected error is thrown
+function checkError(callback, ErrorType) {
+    try {
+        callback();
+        fail("Should have thrown " + ErrorType.name);
+    } catch (e) {
+        if (! (e instanceof ErrorType)) {
+            print("Expected " + ErrorType.name + " got " + e);
+            e.printStackTrace()
+        }
+    }
+}
+
+// non ArrayBuffer as first arg
+checkError(function() { new DataView(344) }, TypeError);
+
+// illegal offset/length values
+checkError(function() { new DataView(buffer, -1) }, RangeError);
+checkError(function() { new DataView(buffer, 15) }, RangeError);
+checkError(function() { new DataView(buffer, 1, 32) }, RangeError);
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/script/currently-failing/OptimisticRecompilationTest.java	Fri Mar 21 17:52:03 2014 +0100
@@ -0,0 +1,171 @@
+/*
+ * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package jdk.nashorn.internal.runtime;
+
+import java.io.ByteArrayOutputStream;
+import java.io.PrintStream;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+import static org.testng.Assert.fail;
+import org.testng.annotations.Test;
+import org.testng.annotations.AfterTest;
+import org.testng.annotations.BeforeTest;
+import javax.script.ScriptEngine;
+import javax.script.ScriptEngineFactory;
+import javax.script.ScriptEngineManager;
+import jdk.nashorn.api.scripting.NashornScriptEngineFactory;
+
+/**
+ * @test
+ * @bug 8037086
+ * @run testng/othervm jdk.nashorn.internal.runtime.OptimisticRecompilationTest
+ */
+public class OptimisticRecompilationTest {
+
+   private ScriptEngine engine;
+   private ByteArrayOutputStream stderr;
+   private PrintStream prevStderr;
+
+   public void runTest(String script, String expectedOutputPattern,
+                       int expectedPatternOccurrence) {
+      try {
+         engine.eval(script);
+      } catch (final Exception se) {
+         se.printStackTrace();
+         fail(se.getMessage());
+      }
+      Pattern deoptimizing = Pattern.compile(expectedOutputPattern);
+      Matcher matcher = deoptimizing.matcher(stderr.toString());
+      int matches = 0;
+      while (matcher.find()) {
+         matches++;
+      }
+      if (matches != expectedPatternOccurrence) {
+         fail("Number of Deoptimizing recompilation is not correct, expected: "
+                    + expectedPatternOccurrence + " and found: " + matches + "\n"
+              + stderr);
+      }
+      stderr.reset();
+   }
+
+   private static String getRecompilationPattern(String type, String value) {
+        return "\\[recompile\\]\\s*RewriteException\\s\\[programPoint\\=(\\d+)\\s"
+           + "returnType=" + type + "\\s\\(" + value + "\\)";
+   }
+
+    @BeforeTest
+    public void setupTest() {
+       stderr = new ByteArrayOutputStream();
+       prevStderr = System.err;
+       System.setErr(new PrintStream(stderr));
+       NashornScriptEngineFactory nashornFactory = null;
+       ScriptEngineManager sm = new ScriptEngineManager();
+       for (ScriptEngineFactory fac : sm.getEngineFactories()) {
+          if (fac instanceof NashornScriptEngineFactory) {
+             nashornFactory = (NashornScriptEngineFactory) fac;
+             break;
+          }
+       }
+       if (nashornFactory == null) {
+          fail("Cannot find nashorn factory!");
+       }
+       String[] options = new String[]{"--log=recompile"};
+       engine = nashornFactory.getScriptEngine(options);
+    }
+
+    @AfterTest
+    public void setErrTest() {
+       System.setErr(prevStderr);
+    }
+
+    @Test
+    public void divisionByZeroTest() {
+       //Check that two Deoptimizing recompilations and RewriteExceptions happened
+       runTest("function f() {var x = { a: 2, b:1 }; x.a = Number.POSITIVE_INFINITY;"
+               + " x.b = 0; print(x.a/x.b);} f()",
+               getRecompilationPattern("double", "Infinity"), 2);
+    }
+
+    @Test
+    public void divisionWithRemainderTest() {
+       //Check that one Deoptimizing recompilation and RewriteException happened
+       runTest("function f() {var x = { a: 7, b:2 }; print(x.a/x.b);} f()",
+               getRecompilationPattern("double", "3.5"), 1);
+    }
+
+    @Test
+    public void infinityMultiplicationTest() {
+       //Check that three Deoptimizing recompilations and RewriteExceptions happened
+       runTest("function f() {var x = { a: Number.POSITIVE_INFINITY, "
+               + "b: Number.POSITIVE_INFINITY}; print(x.a*x.b);} f()",
+               getRecompilationPattern("double", "Infinity"), 3);
+    }
+
+    @Test
+    public void maxValueMultiplicationTest() {
+       runTest("function f() {var x = { a: Number.MAX_VALUE, b: Number.MAX_VALUE};"
+               + " print(x.a*x.b);} f()",
+               getRecompilationPattern("double", "1.7976931348623157E308"), 3);
+    }
+
+    @Test
+    public void divisionByInfinityTest() {
+       //Check that two Deoptimizing recompilations and RewriteExceptions happened
+       runTest("function f() {var x = { a: -1, b: Number.POSITIVE_INFINITY};"
+               + " print(x.a/x.b);} f()",
+               getRecompilationPattern("double", "Infinity"), 2);
+    }
+
+    @Test
+    public void divisionByStringTest() {
+       //Check that three Deoptimizing recompilations and RewriteExceptions happened
+       String str1 = getRecompilationPattern("double", "Infinity");
+       String str2 = getRecompilationPattern("object", "Hello");
+       runTest("function f() {var x = { a: Number.POSITIVE_INFINITY, b: 'Hello'};"
+               + " print(x.a/x.b);} f()", String.format("(?s)%s.*%1$s.*%s", str1, str2), 1);
+    }
+
+    @Test
+    public void nestedFunctionTest() {
+       //Check that one Deoptimizing recompilations and RewriteExceptions happened
+       runTest("var a=3,b,c; function f() {var x = 2, y =1; function g(){ "
+               + "var y = x; var z = a; z = x*y; print(a*b); } g() } f()",
+               getRecompilationPattern("object", "undefined"), 1);
+    }
+
+    @Test
+    public void andTest() {
+       //Check that one Deoptimizing recompilations and RewriteExceptions happened
+       runTest("function f(a,b) { d = a && b; print(d);} f()",
+               "\\[recompile\\]\\sDeoptimizing\\srecompilation\\sof\\s\'f\'", 1);
+    }
+
+    @Test
+    public void functionTest() {
+       //Check that one Deoptimizing recompilations and RewriteExceptions happened
+       runTest("function f(a,b,c) { d = (a + b) * c; print(d);} f()",
+               getRecompilationPattern("double", "NaN"), 1);
+    }
+}
--- a/test/src/jdk/nashorn/api/scripting/ScopeTest.java	Thu Mar 20 16:26:54 2014 +0100
+++ b/test/src/jdk/nashorn/api/scripting/ScopeTest.java	Fri Mar 21 17:52:03 2014 +0100
@@ -245,4 +245,320 @@
         sb.put("x", "newX");
         assertTrue(e.eval("x", ctx).equals("newX"));
     }
+
+    /**
+     * Test multi-threaded access to defined global variables for shared script classes with multiple globals.
+     */
+    @Test
+    public static void multiThreadedVarTest() throws ScriptException, InterruptedException {
+        final ScriptEngineManager m = new ScriptEngineManager();
+        final ScriptEngine e = m.getEngineByName("nashorn");
+        final Bindings b = e.createBindings();
+        final ScriptContext origContext = e.getContext();
+        final ScriptContext newCtxt = new SimpleScriptContext();
+        newCtxt.setBindings(b, ScriptContext.ENGINE_SCOPE);
+        final String sharedScript = "foo";
+
+        assertEquals(e.eval("var foo = 'original context';", origContext), null);
+        assertEquals(e.eval("var foo = 'new context';", newCtxt), null);
+
+        final Thread t1 = new Thread(new ScriptRunner(e, origContext, sharedScript, "original context", 1000));
+        final Thread t2 = new Thread(new ScriptRunner(e, newCtxt, sharedScript, "new context", 1000));
+        t1.start();
+        t2.start();
+        t1.join();
+        t2.join();
+
+        assertEquals(e.eval("var foo = 'newer context';", newCtxt), null);
+        final Thread t3 = new Thread(new ScriptRunner(e, origContext, sharedScript, "original context", 1000));
+        final Thread t4 = new Thread(new ScriptRunner(e, newCtxt, sharedScript, "newer context", 1000));
+
+        t3.start();
+        t4.start();
+        t3.join();
+        t4.join();
+
+        assertEquals(e.eval(sharedScript), "original context");
+        assertEquals(e.eval(sharedScript, newCtxt), "newer context");
+    }
+
+    /**
+     * Test multi-threaded access to undefined global variables for shared script classes with multiple globals.
+     */
+    @Test
+    public static void multiThreadedGlobalTest() throws ScriptException, InterruptedException {
+        final ScriptEngineManager m = new ScriptEngineManager();
+        final ScriptEngine e = m.getEngineByName("nashorn");
+        final Bindings b = e.createBindings();
+        final ScriptContext origContext = e.getContext();
+        final ScriptContext newCtxt = new SimpleScriptContext();
+        newCtxt.setBindings(b, ScriptContext.ENGINE_SCOPE);
+
+        assertEquals(e.eval("foo = 'original context';", origContext), "original context");
+        assertEquals(e.eval("foo = 'new context';", newCtxt), "new context");
+        final String sharedScript = "foo";
+
+        final Thread t1 = new Thread(new ScriptRunner(e, origContext, sharedScript, "original context", 1000));
+        final Thread t2 = new Thread(new ScriptRunner(e, newCtxt, sharedScript, "new context", 1000));
+        t1.start();
+        t2.start();
+        t1.join();
+        t2.join();
+
+        Object obj3 = e.eval("delete foo; foo = 'newer context';", newCtxt);
+        assertEquals(obj3, "newer context");
+        final Thread t3 = new Thread(new ScriptRunner(e, origContext, sharedScript, "original context", 1000));
+        final Thread t4 = new Thread(new ScriptRunner(e, newCtxt, sharedScript, "newer context", 1000));
+
+        t3.start();
+        t4.start();
+        t3.join();
+        t4.join();
+
+        Assert.assertEquals(e.eval(sharedScript), "original context");
+        Assert.assertEquals(e.eval(sharedScript, newCtxt), "newer context");
+    }
+
+    /**
+     * Test multi-threaded access using the postfix ++ operator for shared script classes with multiple globals.
+     */
+    @Test
+    public static void multiThreadedIncTest() throws ScriptException, InterruptedException {
+        final ScriptEngineManager m = new ScriptEngineManager();
+        final ScriptEngine e = m.getEngineByName("nashorn");
+        final Bindings b = e.createBindings();
+        final ScriptContext origContext = e.getContext();
+        final ScriptContext newCtxt = new SimpleScriptContext();
+        newCtxt.setBindings(b, ScriptContext.ENGINE_SCOPE);
+
+        assertEquals(e.eval("var x = 0;", origContext), null);
+        assertEquals(e.eval("var x = 2;", newCtxt), null);
+        final String sharedScript = "x++;";
+
+        final Thread t1 = new Thread(new Runnable() {
+            @Override
+            public void run() {
+                try {
+                    for (int i = 0; i < 1000; i++) {
+                        assertEquals(e.eval(sharedScript, origContext), (double)i);
+                    }
+                } catch (ScriptException se) {
+                    fail(se.toString());
+                }
+            }
+        });
+        final Thread t2 = new Thread(new Runnable() {
+            @Override
+            public void run() {
+                try {
+                    for (int i = 2; i < 1000; i++) {
+                        assertEquals(e.eval(sharedScript, newCtxt), (double)i);
+                    }
+                } catch (ScriptException se) {
+                    fail(se.toString());
+                }
+            }
+        });
+        t1.start();
+        t2.start();
+        t1.join();
+        t2.join();
+    }
+
+    /**
+     * Test multi-threaded access to primitive prototype properties for shared script classes with multiple globals.
+     */
+    @Test
+    public static void multiThreadedPrimitiveTest() throws ScriptException, InterruptedException {
+        final ScriptEngineManager m = new ScriptEngineManager();
+        final ScriptEngine e = m.getEngineByName("nashorn");
+        final Bindings b = e.createBindings();
+        final ScriptContext origContext = e.getContext();
+        final ScriptContext newCtxt = new SimpleScriptContext();
+        newCtxt.setBindings(b, ScriptContext.ENGINE_SCOPE);
+
+        Object obj1 = e.eval("String.prototype.foo = 'original context';", origContext);
+        Object obj2 = e.eval("String.prototype.foo = 'new context';", newCtxt);
+        assertEquals(obj1, "original context");
+        assertEquals(obj2, "new context");
+        final String sharedScript = "''.foo";
+
+        final Thread t1 = new Thread(new ScriptRunner(e, origContext, sharedScript, "original context", 1000));
+        final Thread t2 = new Thread(new ScriptRunner(e, newCtxt, sharedScript, "new context", 1000));
+        t1.start();
+        t2.start();
+        t1.join();
+        t2.join();
+
+        Object obj3 = e.eval("delete String.prototype.foo; Object.prototype.foo = 'newer context';", newCtxt);
+        assertEquals(obj3, "newer context");
+        final Thread t3 = new Thread(new ScriptRunner(e, origContext, sharedScript, "original context", 1000));
+        final Thread t4 = new Thread(new ScriptRunner(e, newCtxt, sharedScript, "newer context", 1000));
+
+        t3.start();
+        t4.start();
+        t3.join();
+        t4.join();
+
+        Assert.assertEquals(e.eval(sharedScript), "original context");
+        Assert.assertEquals(e.eval(sharedScript, newCtxt), "newer context");
+    }
+
+    /**
+     * Test multi-threaded scope function invocation for shared script classes with multiple globals.
+     */
+    @Test
+    public static void multiThreadedFunctionTest() throws ScriptException, InterruptedException {
+        final ScriptEngineManager m = new ScriptEngineManager();
+        final ScriptEngine e = m.getEngineByName("nashorn");
+        final Bindings b = e.createBindings();
+        final ScriptContext origContext = e.getContext();
+        final ScriptContext newCtxt = new SimpleScriptContext();
+        newCtxt.setBindings(b, ScriptContext.ENGINE_SCOPE);
+
+        e.eval(new URLReader(ScopeTest.class.getResource("resources/func.js")), origContext);
+        assertEquals(origContext.getAttribute("scopeVar"), 1);
+        assertEquals(e.eval("scopeTest()"), 1);
+
+        e.eval(new URLReader(ScopeTest.class.getResource("resources/func.js")), newCtxt);
+        assertEquals(newCtxt.getAttribute("scopeVar"), 1);
+        assertEquals(e.eval("scopeTest();", newCtxt), 1);
+
+        assertEquals(e.eval("scopeVar = 3;", newCtxt), 3);
+        assertEquals(newCtxt.getAttribute("scopeVar"), 3);
+
+
+        final Thread t1 = new Thread(new ScriptRunner(e, origContext, "scopeTest()", 1, 1000));
+        final Thread t2 = new Thread(new ScriptRunner(e, newCtxt, "scopeTest()", 3, 1000));
+
+        t1.start();
+        t2.start();
+        t1.join();
+        t2.join();
+
+    }
+
+    /**
+     * Test multi-threaded access to global getters and setters for shared script classes with multiple globals.
+     */
+    @Test
+    public static void getterSetterTest() throws ScriptException, InterruptedException {
+        final ScriptEngineManager m = new ScriptEngineManager();
+        final ScriptEngine e = m.getEngineByName("nashorn");
+        final Bindings b = e.createBindings();
+        final ScriptContext origContext = e.getContext();
+        final ScriptContext newCtxt = new SimpleScriptContext();
+        newCtxt.setBindings(b, ScriptContext.ENGINE_SCOPE);
+        final String sharedScript = "accessor1";
+
+        e.eval(new URLReader(ScopeTest.class.getResource("resources/gettersetter.js")), origContext);
+        assertEquals(e.eval("accessor1 = 1;"), 1);
+        assertEquals(e.eval(sharedScript), 1);
+
+        e.eval(new URLReader(ScopeTest.class.getResource("resources/gettersetter.js")), newCtxt);
+        assertEquals(e.eval("accessor1 = 2;", newCtxt), 2);
+        assertEquals(e.eval(sharedScript, newCtxt), 2);
+
+
+        final Thread t1 = new Thread(new ScriptRunner(e, origContext, sharedScript, 1, 1000));
+        final Thread t2 = new Thread(new ScriptRunner(e, newCtxt, sharedScript, 2, 1000));
+
+        t1.start();
+        t2.start();
+        t1.join();
+        t2.join();
+
+        assertEquals(e.eval(sharedScript), 1);
+        assertEquals(e.eval(sharedScript, newCtxt), 2);
+        assertEquals(e.eval("v"), 1);
+        assertEquals(e.eval("v", newCtxt), 2);
+    }
+
+    /**
+     * Test multi-threaded access to global getters and setters for shared script classes with multiple globals.
+     */
+    @Test
+    public static void getterSetter2Test() throws ScriptException, InterruptedException {
+        final ScriptEngineManager m = new ScriptEngineManager();
+        final ScriptEngine e = m.getEngineByName("nashorn");
+        final Bindings b = e.createBindings();
+        final ScriptContext origContext = e.getContext();
+        final ScriptContext newCtxt = new SimpleScriptContext();
+        newCtxt.setBindings(b, ScriptContext.ENGINE_SCOPE);
+        final String sharedScript = "accessor2";
+
+        e.eval(new URLReader(ScopeTest.class.getResource("resources/gettersetter.js")), origContext);
+        assertEquals(e.eval("accessor2 = 1;"), 1);
+        assertEquals(e.eval(sharedScript), 1);
+
+        e.eval(new URLReader(ScopeTest.class.getResource("resources/gettersetter.js")), newCtxt);
+        assertEquals(e.eval("accessor2 = 2;", newCtxt), 2);
+        assertEquals(e.eval(sharedScript, newCtxt), 2);
+
+
+        final Thread t1 = new Thread(new ScriptRunner(e, origContext, sharedScript, 1, 1000));
+        final Thread t2 = new Thread(new ScriptRunner(e, newCtxt, sharedScript, 2, 1000));
+
+        t1.start();
+        t2.start();
+        t1.join();
+        t2.join();
+
+        assertEquals(e.eval(sharedScript), 1);
+        assertEquals(e.eval(sharedScript, newCtxt), 2);
+        assertEquals(e.eval("x"), 1);
+        assertEquals(e.eval("x", newCtxt), 2);
+    }
+
+    /**
+     * Test "slow" scopes involving {@code with} and {@code eval} statements for shared script classes with multiple globals.
+     */
+    @Test
+    public static void testSlowScope() throws ScriptException, InterruptedException {
+        final ScriptEngineManager m = new ScriptEngineManager();
+        final ScriptEngine e = m.getEngineByName("nashorn");
+
+        for (int i = 0; i < 100; i++) {
+            final Bindings b = e.createBindings();
+            final ScriptContext ctxt = new SimpleScriptContext();
+            ctxt.setBindings(b, ScriptContext.ENGINE_SCOPE);
+
+            e.eval(new URLReader(ScopeTest.class.getResource("resources/witheval.js")), ctxt);
+            assertEquals(e.eval("a", ctxt), 1);
+            assertEquals(b.get("a"), 1);
+            assertEquals(e.eval("b", ctxt), 3);
+            assertEquals(b.get("b"), 3);
+            assertEquals(e.eval("c", ctxt), 10);
+            assertEquals(b.get("c"), 10);
+        }
+    }
+
+    private static class ScriptRunner implements Runnable {
+
+        final ScriptEngine engine;
+        final ScriptContext context;
+        final String source;
+        final Object expected;
+        final int iterations;
+
+        ScriptRunner(final ScriptEngine engine, final ScriptContext context, final String source, final Object expected, final int iterations) {
+            this.engine = engine;
+            this.context = context;
+            this.source = source;
+            this.expected = expected;
+            this.iterations = iterations;
+        }
+
+        @Override
+        public void run() {
+            try {
+                for (int i = 0; i < iterations; i++) {
+                    assertEquals(engine.eval(source, context), expected);
+                }
+            } catch (ScriptException se) {
+                throw new RuntimeException(se);
+            }
+        }
+    }
+
 }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/src/jdk/nashorn/api/scripting/resources/func.js	Fri Mar 21 17:52:03 2014 +0100
@@ -0,0 +1,42 @@
+/*
+ * Copyright (c) 2010, 2014, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+// This script is loaded from jdk.nashorn.api.scripting.ScopeTest to test script class sharing and reuse.
+
+var scopeVar = 1;
+var global = this;
+undefGlobal = this;
+
+function scopeTest() {
+    if (this !== global) {
+        throw new Error("this !== global");
+    }
+    if (this !== undefGlobal) {
+        throw new Error("this !== undefinedGlobal")
+    }
+    return scopeVar;
+}
+
+scopeTest();
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/src/jdk/nashorn/api/scripting/resources/gettersetter.js	Fri Mar 21 17:52:03 2014 +0100
@@ -0,0 +1,38 @@
+/*
+ * Copyright (c) 2010, 2014, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+// This script is loaded from jdk.nashorn.api.scripting.ScopeTest to test script class sharing and reuse.
+
+var v;
+
+Object.defineProperty(this, "accessor1", {
+    get: function() { return v; },
+    set: function(n) { v = n; }
+});
+
+Object.defineProperty(this, "accessor2", {
+    get: function() { return x; },
+    set: function(n) { x = n; }
+});
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/src/jdk/nashorn/api/scripting/resources/witheval.js	Fri Mar 21 17:52:03 2014 +0100
@@ -0,0 +1,60 @@
+/*
+ * Copyright (c) 2010, 2014, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+// This script is loaded from jdk.nashorn.api.scripting.ScopeTest to test script class sharing and reuse.
+
+var a;
+
+function outer(p, e) {
+    eval(e);
+    with(p) {
+        function inner() {
+            a = 1;
+            c = 10;
+            if (a !== 1) {
+                throw new Error("a !== 1");
+            }
+            if (b !== 3) {
+                throw new Error("b !== 3");
+            }
+            if (c !== 10) {
+                throw new Error("c !== 10");
+            }
+        }
+        inner();
+    }
+}
+
+outer({}, "b = 3;");
+
+if (a !== 1) {
+    throw new Error("a !== 1");
+}
+if (b !== 3) {
+    throw new Error("b !== 3");
+}
+if (c !== 10) {
+    throw new Error("c !== 10");
+}
--- a/test/src/jdk/nashorn/internal/codegen/CompilerTest.java	Thu Mar 20 16:26:54 2014 +0100
+++ b/test/src/jdk/nashorn/internal/codegen/CompilerTest.java	Fri Mar 21 17:52:03 2014 +0100
@@ -28,6 +28,7 @@
 import java.io.File;
 import java.io.PrintWriter;
 import java.io.StringWriter;
+import jdk.nashorn.internal.objects.Global;
 import jdk.nashorn.internal.runtime.Context;
 import jdk.nashorn.internal.runtime.ErrorManager;
 import jdk.nashorn.internal.runtime.ScriptFunction;
@@ -58,7 +59,7 @@
     }
 
     private Context context;
-    private ScriptObject global;
+    private Global  global;
 
     @BeforeClass
     public void setupTest() {
@@ -146,7 +147,7 @@
             log("Begin compiling " + file.getAbsolutePath());
         }
 
-        final ScriptObject oldGlobal = Context.getGlobal();
+        final Global oldGlobal = Context.getGlobal();
         final boolean globalChanged = (oldGlobal != global);
 
         try {
--- a/test/src/jdk/nashorn/internal/performance/PerformanceWrapper.java	Thu Mar 20 16:26:54 2014 +0100
+++ b/test/src/jdk/nashorn/internal/performance/PerformanceWrapper.java	Fri Mar 21 17:52:03 2014 +0100
@@ -31,9 +31,9 @@
 import java.util.concurrent.Future;
 import java.util.concurrent.TimeUnit;
 import java.util.concurrent.TimeoutException;
+import jdk.nashorn.internal.objects.Global;
 import jdk.nashorn.internal.runtime.Context;
 import jdk.nashorn.internal.runtime.ScriptFunction;
-import jdk.nashorn.internal.runtime.ScriptObject;
 import jdk.nashorn.internal.runtime.ScriptRuntime;
 
 /**
@@ -89,7 +89,7 @@
     @Override
     protected Object apply(final ScriptFunction target, final Object self) {
         if (_runsPerIteration == 0 && _numberOfIterations == 0) {
-            final ScriptObject global = jdk.nashorn.internal.runtime.Context.getGlobal();
+            final Global global = jdk.nashorn.internal.runtime.Context.getGlobal();
             final ScriptFunction _target = target;
             final Object _self = self;
 
--- a/test/src/jdk/nashorn/internal/runtime/ContextTest.java	Thu Mar 20 16:26:54 2014 +0100
+++ b/test/src/jdk/nashorn/internal/runtime/ContextTest.java	Fri Mar 21 17:52:03 2014 +0100
@@ -29,6 +29,7 @@
 import static org.testng.Assert.assertTrue;
 
 import java.util.Map;
+import jdk.nashorn.internal.objects.Global;
 import jdk.nashorn.internal.runtime.options.Options;
 import org.testng.annotations.Test;
 
@@ -45,7 +46,7 @@
         final Options options = new Options("");
         final ErrorManager errors = new ErrorManager();
         final Context cx = new Context(options, errors, Thread.currentThread().getContextClassLoader());
-        final ScriptObject oldGlobal = Context.getGlobal();
+        final Global oldGlobal = Context.getGlobal();
         Context.setGlobal(cx.createGlobal());
         try {
             String code = "22 + 10";
@@ -65,7 +66,7 @@
         final ErrorManager errors = new ErrorManager();
         final Context cx = new Context(options, errors, Thread.currentThread().getContextClassLoader());
         final boolean strict = cx.getEnv()._strict;
-        final ScriptObject oldGlobal = Context.getGlobal();
+        final Global oldGlobal = Context.getGlobal();
         Context.setGlobal(cx.createGlobal());
 
         try {
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/src/jdk/nashorn/internal/runtime/NoPersistenceCachingTest.java	Fri Mar 21 17:52:03 2014 +0100
@@ -0,0 +1,135 @@
+/*
+ * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package jdk.nashorn.internal.runtime;
+
+import java.io.ByteArrayOutputStream;
+import java.io.PrintStream;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+import static org.testng.Assert.fail;
+import org.testng.annotations.Test;
+
+import javax.script.ScriptContext;
+import javax.script.ScriptEngine;
+import javax.script.ScriptEngineFactory;
+import javax.script.ScriptEngineManager;
+import javax.script.SimpleScriptContext;
+import jdk.nashorn.api.scripting.NashornScriptEngineFactory;
+import org.testng.annotations.AfterTest;
+import org.testng.annotations.BeforeTest;
+
+/**
+ * @test
+ * @bug 8037378
+ * @summary Sanity tests for no persistence caching
+ * @run testng/othervm jdk.nashorn.internal.runtime.NoPersistenceCachingTest
+ */
+public class NoPersistenceCachingTest {
+
+   private ScriptEngine engine;
+   private ScriptContext context1, context2, context3;
+   private ByteArrayOutputStream stderr;
+   private PrintStream prevStderr;
+
+   @BeforeTest
+   public void setupTest() {
+      stderr = new ByteArrayOutputStream();
+      prevStderr = System.err;
+      System.setErr(new PrintStream(stderr));
+      NashornScriptEngineFactory nashornFactory = null;
+      ScriptEngineManager sm = new ScriptEngineManager();
+      for (ScriptEngineFactory fac : sm.getEngineFactories()) {
+         if (fac instanceof NashornScriptEngineFactory) {
+            nashornFactory = (NashornScriptEngineFactory) fac;
+            break;
+         }
+      }
+      if (nashornFactory == null) {
+         fail("Cannot find nashorn factory!");
+      }
+      String[] options = new String[]{"--log=compiler:finest"};
+      engine = nashornFactory.getScriptEngine(options);
+      context1 = engine.getContext();
+      context2 = new SimpleScriptContext();
+      context2.setBindings(engine.createBindings(), ScriptContext.ENGINE_SCOPE);
+      context3 = new SimpleScriptContext();
+      context3.setBindings(engine.createBindings(), ScriptContext.ENGINE_SCOPE);
+   }
+
+   @AfterTest
+   public void setErrTest() {
+      System.setErr(prevStderr);
+   }
+
+   public void runTest(int numberOfContext, String expectedOutputPattern,
+                       int expectedPatternOccurrence) {
+
+      try {
+         switch (numberOfContext) {
+         case 2:
+            String scriptTwoContexts = "print('HelloTwoContexts')";
+            engine.eval(scriptTwoContexts, context1);
+            engine.eval(scriptTwoContexts, context2);
+            break;
+         case 3:
+            String scriptThreeContexts = "print('HelloThreeContexts')";
+            engine.eval(scriptThreeContexts, context1);
+            engine.eval(scriptThreeContexts, context2);
+            engine.eval(scriptThreeContexts, context3);
+            break;
+         }
+      } catch (final Exception se) {
+         se.printStackTrace();
+         fail(se.getMessage());
+      }
+      Pattern deoptimizing = Pattern.compile(expectedOutputPattern);
+      Matcher matcher = deoptimizing.matcher(stderr.toString());
+      int matches = 0;
+      while (matcher.find()) {
+         matches++;
+      }
+      if (matches != expectedPatternOccurrence) {
+         fail("Number of cache hit is not correct, expected: "
+                    + expectedPatternOccurrence + " and found: " + matches + "\n"
+              + stderr);
+      }
+      stderr.reset();
+   }
+
+   private static String getCodeCachePattern() {
+      return ("\\[compiler\\]\\sCode\\scache\\shit\\sfor\\s<eval>\\savoiding\\srecompile.");
+   }
+
+    @Test
+    public void twoContextTest() {
+       runTest(2, getCodeCachePattern(), 1);
+
+    }
+
+    @Test
+    public void threeContextTest() {
+       runTest(3, getCodeCachePattern(), 2);
+    }
+}
--- a/test/src/jdk/nashorn/internal/runtime/OptimisticRecompilationTest.java	Thu Mar 20 16:26:54 2014 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,171 +0,0 @@
-/*
- * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.  Oracle designates this
- * particular file as subject to the "Classpath" exception as provided
- * by Oracle in the LICENSE file that accompanied this code.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-package jdk.nashorn.internal.runtime;
-
-import java.io.ByteArrayOutputStream;
-import java.io.PrintStream;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-import static org.testng.Assert.fail;
-import org.testng.annotations.Test;
-import org.testng.annotations.AfterTest;
-import org.testng.annotations.BeforeTest;
-import javax.script.ScriptEngine;
-import javax.script.ScriptEngineFactory;
-import javax.script.ScriptEngineManager;
-import jdk.nashorn.api.scripting.NashornScriptEngineFactory;
-
-/**
- * @test
- * @bug 8037086
- * @run testng/othervm jdk.nashorn.internal.runtime.OptimisticRecompilationTest
- */
-public class OptimisticRecompilationTest {
-
-   private ScriptEngine engine;
-   private ByteArrayOutputStream stderr;
-   private PrintStream prevStderr;
-
-   public void runTest(String script, String expectedOutputPattern,
-                       int expectedPatternOccurrence) {
-      try {
-         engine.eval(script);
-      } catch (final Exception se) {
-         se.printStackTrace();
-         fail(se.getMessage());
-      }
-      Pattern deoptimizing = Pattern.compile(expectedOutputPattern);
-      Matcher matcher = deoptimizing.matcher(stderr.toString());
-      int matches = 0;
-      while (matcher.find()) {
-         matches++;
-      }
-      if (matches != expectedPatternOccurrence) {
-         fail("Number of Deoptimizing recompilation is not correct, expected: "
-                    + expectedPatternOccurrence + " and found: " + matches + "\n"
-              + stderr);
-      }
-      stderr.reset();
-   }
-
-   private static String getRecompilationPattern(String type, String value) {
-        return "\\[recompile\\]\\s*RewriteException\\s\\[programPoint\\=(\\d+)\\s"
-           + "returnType=" + type + "\\s\\(" + value + "\\)";
-   }
-
-    @BeforeTest
-    public void setupTest() {
-       stderr = new ByteArrayOutputStream();
-       prevStderr = System.err;
-       System.setErr(new PrintStream(stderr));
-       NashornScriptEngineFactory nashornFactory = null;
-       ScriptEngineManager sm = new ScriptEngineManager();
-       for (ScriptEngineFactory fac : sm.getEngineFactories()) {
-          if (fac instanceof NashornScriptEngineFactory) {
-             nashornFactory = (NashornScriptEngineFactory) fac;
-             break;
-          }
-       }
-       if (nashornFactory == null) {
-          fail("Cannot find nashorn factory!");
-       }
-       String[] options = new String[]{"--log=recompile"};
-       engine = nashornFactory.getScriptEngine(options);
-    }
-
-    @AfterTest
-    public void setErrTest() {
-       System.setErr(prevStderr);
-    }
-
-    @Test
-    public void divisionByZeroTest() {
-       //Check that two Deoptimizing recompilations and RewriteExceptions happened
-       runTest("function f() {var x = { a: 2, b:1 }; x.a = Number.POSITIVE_INFINITY;"
-               + " x.b = 0; print(x.a/x.b);} f()",
-               getRecompilationPattern("double", "Infinity"), 2);
-    }
-
-    @Test
-    public void divisionWithRemainderTest() {
-       //Check that one Deoptimizing recompilation and RewriteException happened
-       runTest("function f() {var x = { a: 7, b:2 }; print(x.a/x.b);} f()",
-               getRecompilationPattern("double", "3.5"), 1);
-    }
-
-    @Test
-    public void infinityMultiplicationTest() {
-       //Check that three Deoptimizing recompilations and RewriteExceptions happened
-       runTest("function f() {var x = { a: Number.POSITIVE_INFINITY, "
-               + "b: Number.POSITIVE_INFINITY}; print(x.a*x.b);} f()",
-               getRecompilationPattern("double", "Infinity"), 3);
-    }
-
-    @Test
-    public void maxValueMultiplicationTest() {
-       runTest("function f() {var x = { a: Number.MAX_VALUE, b: Number.MAX_VALUE};"
-               + " print(x.a*x.b);} f()",
-               getRecompilationPattern("double", "1.7976931348623157E308"), 3);
-    }
-
-    @Test
-    public void divisionByInfinityTest() {
-       //Check that two Deoptimizing recompilations and RewriteExceptions happened
-       runTest("function f() {var x = { a: -1, b: Number.POSITIVE_INFINITY};"
-               + " print(x.a/x.b);} f()",
-               getRecompilationPattern("double", "Infinity"), 2);
-    }
-
-    @Test
-    public void divisionByStringTest() {
-       //Check that three Deoptimizing recompilations and RewriteExceptions happened
-       String str1 = getRecompilationPattern("double", "Infinity");
-       String str2 = getRecompilationPattern("object", "Hello");
-       runTest("function f() {var x = { a: Number.POSITIVE_INFINITY, b: 'Hello'};"
-               + " print(x.a/x.b);} f()", String.format("(?s)%s.*%1$s.*%s", str1, str2), 1);
-    }
-
-    @Test
-    public void nestedFunctionTest() {
-       //Check that one Deoptimizing recompilations and RewriteExceptions happened
-       runTest("var a=3,b,c; function f() {var x = 2, y =1; function g(){ "
-               + "var y = x; var z = a; z = x*y; print(a*b); } g() } f()",
-               getRecompilationPattern("object", "undefined"), 1);
-    }
-
-    @Test
-    public void andTest() {
-       //Check that one Deoptimizing recompilations and RewriteExceptions happened
-       runTest("function f(a,b) { d = a && b; print(d);} f()",
-               "\\[recompile\\]\\sDeoptimizing\\srecompilation\\sof\\s\'f\'", 1);
-    }
-
-    @Test
-    public void functionTest() {
-       //Check that one Deoptimizing recompilations and RewriteExceptions happened
-       runTest("function f(a,b,c) { d = (a + b) * c; print(d);} f()",
-               getRecompilationPattern("double", "NaN"), 1);
-    }
-}
--- a/test/src/jdk/nashorn/internal/test/framework/SharedContextEvaluator.java	Thu Mar 20 16:26:54 2014 +0100
+++ b/test/src/jdk/nashorn/internal/test/framework/SharedContextEvaluator.java	Fri Mar 21 17:52:03 2014 +0100
@@ -34,10 +34,10 @@
 import java.io.OutputStream;
 import java.io.PrintWriter;
 import jdk.nashorn.api.scripting.NashornException;
+import jdk.nashorn.internal.objects.Global;
 import jdk.nashorn.internal.runtime.Context;
 import jdk.nashorn.internal.runtime.ErrorManager;
 import jdk.nashorn.internal.runtime.ScriptFunction;
-import jdk.nashorn.internal.runtime.ScriptObject;
 import jdk.nashorn.internal.runtime.ScriptRuntime;
 import jdk.nashorn.internal.runtime.Source;
 import jdk.nashorn.internal.runtime.options.Options;
@@ -110,12 +110,12 @@
 
     @Override
     public int run(final OutputStream out, final OutputStream err, final String[] args) throws IOException {
-        final ScriptObject oldGlobal = Context.getGlobal();
+        final Global oldGlobal = Context.getGlobal();
         try {
             ctxOut.setDelegatee(out);
             ctxErr.setDelegatee(err);
             final ErrorManager errors = context.getErrorManager();
-            final ScriptObject global = context.createGlobal();
+            final Global global = context.createGlobal();
             Context.setGlobal(global);
 
             // For each file on the command line.