CodeInstaller.java revision 953:221a84ef44c0
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 */ 25 26package jdk.nashorn.internal.runtime; 27 28import java.util.Collection; 29import java.util.Map; 30import jdk.nashorn.internal.codegen.ClassEmitter; 31 32/** 33 * Interface for installing classes passed to the compiler. 34 * As only the code generating package (i.e. Context) knows about 35 * the ScriptLoader and it would be a security hazard otherwise 36 * the Compiler is given an installation interface for its code. 37 * <p> 38 * The compiler still retains most of the state around code emission 39 * and management internally, so this is to avoid passing around any 40 * logic that isn't directly related to installing a class 41 * @param <T> owner class type for this code installer 42 * 43 */ 44public interface CodeInstaller<T> { 45 /** 46 * Return the owner for the CodeInstaller, e.g. a {@link Context} 47 * @return owner 48 */ 49 public T getOwner(); 50 51 /** 52 * Install a class. 53 * @param className name of the class with / separation 54 * @param bytecode bytecode 55 * @return the installed class 56 */ 57 public Class<?> install(final String className, final byte[] bytecode); 58 59 /** 60 * Initialize already installed classes. 61 * @param classes the class to initialize 62 * @param source the source object for the classes 63 * @param constants the runtime constants for the classes 64 */ 65 public void initialize(final Collection<Class<?>> classes, final Source source, final Object[] constants); 66 67 /** 68 * Verify generated bytecode before emission. This is called back from the 69 * {@link ClassEmitter} or the {@link Compiler}. If the "--verify-code" parameter 70 * hasn't been given, this is a nop 71 * 72 * @param code bytecode to verify 73 */ 74 public void verify(final byte[] code); 75 76 /** 77 * Get next unique script id 78 * @return unique script id 79 */ 80 public long getUniqueScriptId(); 81 82 /** 83 * Get next unique eval id 84 * @return unique eval id 85 */ 86 public long getUniqueEvalId(); 87 88 /** 89 * Store a compiled script for later reuse 90 * @param source the script source 91 * @param mainClassName the main class name 92 * @param classBytes map of class names to class bytes 93 * @param constants constants array 94 */ 95 public void storeCompiledScript(Source source, String mainClassName, Map<String, byte[]> classBytes, Object[] constants); 96} 97