Thu, 24 May 2018 16:39:31 +0800
Merge
aoqi@0 | 1 | /* |
aoqi@0 | 2 | * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. |
aoqi@0 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
aoqi@0 | 4 | * |
aoqi@0 | 5 | * This code is free software; you can redistribute it and/or modify it |
aoqi@0 | 6 | * under the terms of the GNU General Public License version 2 only, as |
aoqi@0 | 7 | * published by the Free Software Foundation. Oracle designates this |
aoqi@0 | 8 | * particular file as subject to the "Classpath" exception as provided |
aoqi@0 | 9 | * by Oracle in the LICENSE file that accompanied this code. |
aoqi@0 | 10 | * |
aoqi@0 | 11 | * This code is distributed in the hope that it will be useful, but WITHOUT |
aoqi@0 | 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
aoqi@0 | 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
aoqi@0 | 14 | * version 2 for more details (a copy is included in the LICENSE file that |
aoqi@0 | 15 | * accompanied this code). |
aoqi@0 | 16 | * |
aoqi@0 | 17 | * You should have received a copy of the GNU General Public License version |
aoqi@0 | 18 | * 2 along with this work; if not, write to the Free Software Foundation, |
aoqi@0 | 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
aoqi@0 | 20 | * |
aoqi@0 | 21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
aoqi@0 | 22 | * or visit www.oracle.com if you need additional information or have any |
aoqi@0 | 23 | * questions. |
aoqi@0 | 24 | */ |
aoqi@0 | 25 | |
aoqi@0 | 26 | package jdk.nashorn.internal.runtime; |
aoqi@0 | 27 | |
attila@963 | 28 | import java.util.Collection; |
aoqi@0 | 29 | import java.util.Map; |
aoqi@0 | 30 | import jdk.nashorn.internal.codegen.ClassEmitter; |
aoqi@0 | 31 | |
aoqi@0 | 32 | /** |
aoqi@0 | 33 | * Interface for installing classes passed to the compiler. |
aoqi@0 | 34 | * As only the code generating package (i.e. Context) knows about |
aoqi@0 | 35 | * the ScriptLoader and it would be a security hazard otherwise |
aoqi@0 | 36 | * the Compiler is given an installation interface for its code. |
aoqi@0 | 37 | * <p> |
aoqi@0 | 38 | * The compiler still retains most of the state around code emission |
aoqi@0 | 39 | * and management internally, so this is to avoid passing around any |
aoqi@0 | 40 | * logic that isn't directly related to installing a class |
aoqi@0 | 41 | * |
aoqi@0 | 42 | */ |
attila@1543 | 43 | public interface CodeInstaller { |
aoqi@0 | 44 | /** |
attila@1543 | 45 | * Return the {@link Context} associated with this code installer. |
attila@1543 | 46 | * @return the context. |
aoqi@0 | 47 | */ |
attila@1543 | 48 | public Context getContext(); |
aoqi@0 | 49 | |
aoqi@0 | 50 | /** |
attila@963 | 51 | * Install a class. |
aoqi@0 | 52 | * @param className name of the class with / separation |
aoqi@0 | 53 | * @param bytecode bytecode |
aoqi@0 | 54 | * @return the installed class |
aoqi@0 | 55 | */ |
attila@963 | 56 | public Class<?> install(final String className, final byte[] bytecode); |
attila@963 | 57 | |
attila@963 | 58 | /** |
attila@963 | 59 | * Initialize already installed classes. |
attila@963 | 60 | * @param classes the class to initialize |
attila@963 | 61 | * @param source the source object for the classes |
attila@963 | 62 | * @param constants the runtime constants for the classes |
attila@963 | 63 | */ |
attila@963 | 64 | public void initialize(final Collection<Class<?>> classes, final Source source, final Object[] constants); |
aoqi@0 | 65 | |
aoqi@0 | 66 | /** |
aoqi@0 | 67 | * Verify generated bytecode before emission. This is called back from the |
aoqi@0 | 68 | * {@link ClassEmitter} or the {@link Compiler}. If the "--verify-code" parameter |
aoqi@0 | 69 | * hasn't been given, this is a nop |
aoqi@0 | 70 | * |
aoqi@0 | 71 | * @param code bytecode to verify |
aoqi@0 | 72 | */ |
aoqi@0 | 73 | public void verify(final byte[] code); |
aoqi@0 | 74 | |
aoqi@0 | 75 | /** |
aoqi@0 | 76 | * Get next unique script id |
aoqi@0 | 77 | * @return unique script id |
aoqi@0 | 78 | */ |
aoqi@0 | 79 | public long getUniqueScriptId(); |
aoqi@0 | 80 | |
aoqi@0 | 81 | /** |
aoqi@0 | 82 | * Store a compiled script for later reuse |
lagergren@1028 | 83 | * |
lagergren@1028 | 84 | * @param cacheKey key to use in cache |
aoqi@0 | 85 | * @param source the script source |
aoqi@0 | 86 | * @param mainClassName the main class name |
aoqi@0 | 87 | * @param classBytes map of class names to class bytes |
sundar@1371 | 88 | * @param initializers compilation id -> FunctionInitializer map |
aoqi@0 | 89 | * @param constants constants array |
lagergren@1028 | 90 | * @param compilationId compilation id |
aoqi@0 | 91 | */ |
lagergren@1028 | 92 | public void storeScript(final String cacheKey, final Source source, final String mainClassName, final Map<String, byte[]> classBytes, |
lagergren@1028 | 93 | final Map<Integer, FunctionInitializer> initializers, final Object[] constants, final int compilationId); |
attila@963 | 94 | |
attila@963 | 95 | /** |
attila@963 | 96 | * Load a previously compiled script |
attila@963 | 97 | * @param source the script source |
attila@963 | 98 | * @param functionKey the function id and signature |
attila@963 | 99 | * @return compiled script data |
attila@963 | 100 | */ |
attila@963 | 101 | public StoredScript loadScript(Source source, String functionKey); |
attila@1030 | 102 | |
attila@1030 | 103 | /** |
attila@1030 | 104 | * Returns a new code installer that shares most of the functionality of this code installer, but uses a |
attila@1030 | 105 | * new, independent class loader. |
attila@1030 | 106 | * @return a new code installer with a new independent class loader. |
attila@1030 | 107 | */ |
attila@1543 | 108 | public CodeInstaller withNewLoader(); |
attila@1030 | 109 | |
attila@1030 | 110 | /** |
attila@1030 | 111 | * Returns true if this code installer is compatible with the other code installer. Compatibility is expected to be |
attila@1030 | 112 | * an equivalence relation, and installers are supposed to be compatible with those they create using |
attila@1030 | 113 | * {@link #withNewLoader()}. |
attila@1030 | 114 | * @param other the other code installer tested for compatibility with this code installer. |
attila@1030 | 115 | * @return true if this code installer is compatible with the other code installer. |
attila@1030 | 116 | */ |
attila@1543 | 117 | public boolean isCompatibleWith(CodeInstaller other); |
attila@1030 | 118 | |
aoqi@0 | 119 | } |