src/jdk/nashorn/internal/runtime/StructureLoader.java

Fri, 05 Jul 2013 14:38:04 +0530

author
sundar
date
Fri, 05 Jul 2013 14:38:04 +0530
changeset 414
ec84ba68ad39
parent 242
b754fb89367d
child 552
8b0914b25430
permissions
-rw-r--r--

8019947: inherited property invalidation does not work with two globals in same context
Reviewed-by: jlaskey, lagergren, hannesw, attila

     1 /*
     2  * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.  Oracle designates this
     8  * particular file as subject to the "Classpath" exception as provided
     9  * by Oracle in the LICENSE file that accompanied this code.
    10  *
    11  * This code is distributed in the hope that it will be useful, but WITHOUT
    12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    14  * version 2 for more details (a copy is included in the LICENSE file that
    15  * accompanied this code).
    16  *
    17  * You should have received a copy of the GNU General Public License version
    18  * 2 along with this work; if not, write to the Free Software Foundation,
    19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    20  *
    21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    22  * or visit www.oracle.com if you need additional information or have any
    23  * questions.
    24  */
    26 package jdk.nashorn.internal.runtime;
    28 import static jdk.nashorn.internal.codegen.Compiler.SCRIPTS_PACKAGE;
    29 import static jdk.nashorn.internal.codegen.Compiler.binaryName;
    30 import static jdk.nashorn.internal.codegen.CompilerConstants.JS_OBJECT_PREFIX;
    32 import java.security.ProtectionDomain;
    33 import jdk.nashorn.internal.codegen.ObjectClassGenerator;
    35 /**
    36  * Responsible for on the fly construction of structure classes.
    37  *
    38  */
    39 final class StructureLoader extends NashornLoader {
    40     private static final String JS_OBJECT_PREFIX_EXTERNAL = binaryName(SCRIPTS_PACKAGE) + '.' + JS_OBJECT_PREFIX.symbolName();
    42     /**
    43      * Constructor.
    44      */
    45     StructureLoader(final ClassLoader parent, final Context context) {
    46         super(parent, context);
    47     }
    49     @Override
    50     protected synchronized Class<?> loadClass(final String name, final boolean resolve) throws ClassNotFoundException {
    51         // check the cache first
    52         final Class<?> loadedClass = findLoadedClass(name);
    53         if (loadedClass != null) {
    54             if (resolve) {
    55                 resolveClass(loadedClass);
    56             }
    57             return loadedClass;
    58         }
    60         return super.loadClassTrusted(name, resolve);
    61     }
    63     @Override
    64     protected Class<?> findClass(final String name) throws ClassNotFoundException {
    65         if (name.startsWith(JS_OBJECT_PREFIX_EXTERNAL)) {
    66             return generateClass(name, name.substring(JS_OBJECT_PREFIX_EXTERNAL.length()));
    67         }
    68         return super.findClass(name);
    69     }
    71     /**
    72      * Generate a layout class.
    73      * @param name       Name of class.
    74      * @param descriptor Layout descriptor.
    75      * @return Generated class.
    76      */
    77     private Class<?> generateClass(final String name, final String descriptor) {
    78         Context context = getContext();
    80         if (context == null) {
    81             context = Context.getContextTrusted();
    82         }
    84         final byte[] code = new ObjectClassGenerator(context).generate(descriptor);
    85         return defineClass(name, code, 0, code.length, new ProtectionDomain(null, getPermissions(null)));
    86     }
    87 }

mercurial