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 package jdk.nashorn.internal.ir; 26 27 import jdk.nashorn.internal.codegen.types.Type; 28 29 /** 30 * Is this a node that can be optimistically typed? This means that it 31 * has a probable type but it's not available through static analysis 32 * 33 * The follow nodes are optimistic, with reasons therefore given within 34 * parenthesis 35 * 36 * @see IndexNode (dynamicGetIndex) 37 * @see BinaryNode (local calculations to strongly typed bytecode) 38 * @see UnaryNode (local calculations to strongly typed bytecode) 39 * @see CallNode (dynamicCall) 40 * @see AccessNode (dynamicGet) 41 * @see IdentNode (dynamicGet) 42 */ 43 public interface Optimistic { 44 /** 45 * Unique node ID that is associated with an invokedynamic call that mail 46 * fail and its callsite. This is so that nodes can be regenerated less 47 * pessimistically the next generation if an assumption failed 48 * 49 * @return unique node id 50 */ 51 public int getProgramPoint(); 52 53 /** 54 * Set the node number for this node, associating with a unique per-function 55 * program point 56 * @param programPoint the node number 57 * @return new node, or same if unchanged 58 */ 59 public Optimistic setProgramPoint(final int programPoint); 60 61 /** 62 * Is it possible for this particular implementor to actually have any optimism? 63 * SHIFT operators for instance are binary nodes, but never optimistic. Multiply 64 * operators are. We might want to refurbish the type hierarchy to fix this. 65 * @return true if theoretically optimistic 66 */ 67 public boolean canBeOptimistic(); 68 69 /** 70 * Get the most optimistic type for this node. Typically we start out as 71 * an int, and then at runtime we bump this up to number and then Object 72 * 73 * @return optimistic type to be used in code generation 74 */ 75 public Type getMostOptimisticType(); 76 77 /** 78 * Most pessimistic type that is guaranteed to be safe. Typically this is 79 * number for arithmetic operations that can overflow, or Object for an add 80 * 81 * @return pessimistic type guaranteed to never overflow 82 */ 83 public Type getMostPessimisticType(); 84 85 /** 86 * Set the override type 87 * 88 * @param type the type 89 * @return a node equivalent to this one except for the requested change. 90 */ 91 public Optimistic setType(final Type type); 92 }