1 /* 2 * Copyright (c) 2010, 2014, 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 26 package jdk.nashorn.internal.runtime; 27 28 import jdk.nashorn.internal.objects.annotations.SpecializedFunction; 29 import jdk.nashorn.internal.objects.annotations.SpecializedFunction.LinkLogic; 30 31 /** 32 * This is an interface for classes that need custom linkage logic. This means Native objects 33 * that contain optimistic native methods, that need special/extra rules for linking, guards and 34 * SwitchPointing, known and internal to the Native object for its linkage 35 */ 36 public interface OptimisticBuiltins { 37 38 /** 39 * Return an instance of the linking logic we need for a particular LinkLogic 40 * subclass, gotten from the compile time annotation of a specialized builtin method 41 * No assumptions can be made about the lifetime of the instance. The receiver may 42 * keep it as a perpetual final instance field or create new linking logic depending 43 * on its current state for each call, depending on if the global state has changed 44 * or other factors 45 * 46 * @param clazz linking logic class 47 * @return linking logic instance for this class 48 */ 49 public SpecializedFunction.LinkLogic getLinkLogic(final Class<? extends LinkLogic> clazz); 50 51 /** 52 * Does this link logic vary depending on which instance we are working with. 53 * Then we have to sort out certain primitives, as they are created as new 54 * objects in the wrapFilter by JavaScript semantics. An example of instance only 55 * assumptions are switchPoints per instance, as in NativeArray. NativeString is 56 * fine, as it's only static. 57 * 58 * TODO: finer granularity on this, on the function level so certain functions 59 * are forbidden only. Currently we don't have enough specialization to bump into this 60 * 61 * @return true if there are per instance assumptions for the optimism 62 */ 63 public boolean hasPerInstanceAssumptions(); 64 65 }