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 
  26 package jdk.nashorn.internal.runtime.linker;
  27 
  28 import java.lang.invoke.MethodHandles;
  29 import java.lang.invoke.MethodHandles.Lookup;
  30 import java.lang.invoke.MethodType;
  31 import java.lang.ref.Reference;
  32 import java.lang.ref.WeakReference;
  33 import java.security.AccessControlContext;
  34 import java.security.AccessController;
  35 import java.security.PrivilegedAction;
  36 import java.util.Collections;
  37 import java.util.Map;
  38 import java.util.WeakHashMap;
  39 import java.util.concurrent.ConcurrentHashMap;
  40 import java.util.concurrent.ConcurrentMap;
  41 import java.util.stream.Stream;
  42 import jdk.dynalink.CallSiteDescriptor;
  43 import jdk.dynalink.CompositeOperation;
  44 import jdk.dynalink.NamedOperation;
  45 import jdk.dynalink.Operation;
  46 import jdk.dynalink.StandardOperation;
  47 import jdk.nashorn.internal.ir.debug.NashornTextifier;
  48 import jdk.nashorn.internal.runtime.AccessControlContextFactory;
  49 import jdk.nashorn.internal.runtime.ScriptRuntime;
  50 
  51 /**
  52  * Nashorn-specific implementation of Dynalink's {@link CallSiteDescriptor}.
  53  * The reason we have our own subclass is that we're storing flags in an
  54  * additional primitive field. The class also exposes some useful utilities in
  55  * form of static methods.
  56  */
  57 public final class NashornCallSiteDescriptor extends CallSiteDescriptor {
  58     // Lowest three bits describe the operation
  59     /** Property getter operation {@code obj.prop} */
  60     public static final int GET_PROPERTY        = 0;
  61     /** Element getter operation {@code obj[index]} */
  62     public static final int GET_ELEMENT         = 1;
  63     /** Property getter operation, subsequently invoked {@code obj.prop()} */
  64     public static final int GET_METHOD_PROPERTY = 2;
  65     /** Element getter operation, subsequently invoked {@code obj[index]()} */
  66     public static final int GET_METHOD_ELEMENT  = 3;
  67     /** Property setter operation {@code obj.prop = value} */
  68     public static final int SET_PROPERTY        = 4;
  69     /** Element setter operation {@code obj[index] = value} */
  70     public static final int SET_ELEMENT         = 5;
  71     /** Call operation {@code fn(args...)} */
  72     public static final int CALL                = 6;
  73     /** New operation {@code new Constructor(args...)} */
  74     public static final int NEW                 = 7;
  75 
  76     private static final int OPERATION_MASK = 7;
  77 
  78     // Correspond to the operation indices above.
  79     private static final Operation[] OPERATIONS = new Operation[] {
  80         new CompositeOperation(StandardOperation.GET_PROPERTY, StandardOperation.GET_ELEMENT, StandardOperation.GET_METHOD),
  81         new CompositeOperation(StandardOperation.GET_ELEMENT, StandardOperation.GET_PROPERTY, StandardOperation.GET_METHOD),
  82         new CompositeOperation(StandardOperation.GET_METHOD, StandardOperation.GET_PROPERTY, StandardOperation.GET_ELEMENT),
  83         new CompositeOperation(StandardOperation.GET_METHOD, StandardOperation.GET_ELEMENT, StandardOperation.GET_PROPERTY),
  84         new CompositeOperation(StandardOperation.SET_PROPERTY, StandardOperation.SET_ELEMENT),
  85         new CompositeOperation(StandardOperation.SET_ELEMENT, StandardOperation.SET_PROPERTY),
  86         StandardOperation.CALL,
  87         StandardOperation.NEW
  88     };
  89 
  90     /** Flags that the call site references a scope variable (it's an identifier reference or a var declaration, not a
  91      * property access expression. */
  92     public static final int CALLSITE_SCOPE         = 1 << 3;
  93     /** Flags that the call site is in code that uses ECMAScript strict mode. */
  94     public static final int CALLSITE_STRICT        = 1 << 4;
  95     /** Flags that a property getter or setter call site references a scope variable that is located at a known distance
  96      * in the scope chain. Such getters and setters can often be linked more optimally using these assumptions. */
  97     public static final int CALLSITE_FAST_SCOPE    = 1 << 5;
  98     /** Flags that a callsite type is optimistic, i.e. we might get back a wider return value than encoded in the
  99      * descriptor, and in that case we have to throw an UnwarrantedOptimismException */
 100     public static final int CALLSITE_OPTIMISTIC    = 1 << 6;
 101     /** Is this really an apply that we try to call as a call? */
 102     public static final int CALLSITE_APPLY_TO_CALL = 1 << 7;
 103     /** Does this a callsite for a variable declaration? */
 104     public static final int CALLSITE_DECLARE       = 1 << 8;
 105 
 106     /** Flags that the call site is profiled; Contexts that have {@code "profile.callsites"} boolean property set emit
 107      * code where call sites have this flag set. */
 108     public static final int CALLSITE_PROFILE         = 1 << 9;
 109     /** Flags that the call site is traced; Contexts that have {@code "trace.callsites"} property set emit code where
 110      * call sites have this flag set. */
 111     public static final int CALLSITE_TRACE           = 1 << 10;
 112     /** Flags that the call site linkage miss (and thus, relinking) is traced; Contexts that have the keyword
 113      * {@code "miss"} in their {@code "trace.callsites"} property emit code where call sites have this flag set. */
 114     public static final int CALLSITE_TRACE_MISSES    = 1 << 11;
 115     /** Flags that entry/exit to/from the method linked at call site are traced; Contexts that have the keyword
 116      * {@code "enterexit"} in their {@code "trace.callsites"} property emit code where call sites have this flag set. */
 117     public static final int CALLSITE_TRACE_ENTEREXIT = 1 << 12;
 118     /** Flags that values passed as arguments to and returned from the method linked at call site are traced; Contexts
 119      * that have the keyword {@code "values"} in their {@code "trace.callsites"} property emit code where call sites
 120      * have this flag set. */
 121     public static final int CALLSITE_TRACE_VALUES    = 1 << 13;
 122 
 123     //we could have more tracing flags here, for example CALLSITE_TRACE_SCOPE, but bits are a bit precious
 124     //right now given the program points
 125 
 126     /**
 127      * Number of bits the program point is shifted to the left in the flags (lowest bit containing a program point).
 128      * Always one larger than the largest flag shift. Note that introducing a new flag halves the number of program
 129      * points we can have.
 130      * TODO: rethink if we need the various profile/trace flags or the linker can use the Context instead to query its
 131      * trace/profile settings.
 132      */
 133     public static final int CALLSITE_PROGRAM_POINT_SHIFT = 14;
 134 
 135     /**
 136      * Maximum program point value. We have 18 bits left over after flags, and
 137      * it should be plenty. Program points are local to a single function. Every
 138      * function maps to a single JVM bytecode method that can have at most 65535
 139      * bytes. (Large functions are synthetically split into smaller functions.)
 140      * A single invokedynamic is 5 bytes; even if a method consists of only
 141      * invokedynamic instructions that leaves us with at most 65535/5 = 13107
 142      * program points for the largest single method; those can be expressed on
 143      * 14 bits. It is true that numbering of program points is independent of
 144      * bytecode representation, but if a function would need more than ~14 bits
 145      * for the program points, then it is reasonable to presume splitter
 146      * would've split it into several smaller functions already.
 147      */
 148     public static final int MAX_PROGRAM_POINT_VALUE = (1 << 32 - CALLSITE_PROGRAM_POINT_SHIFT) - 1;
 149 
 150     /**
 151      * Flag mask to get the program point flags
 152      */
 153     public static final int FLAGS_MASK = (1 << CALLSITE_PROGRAM_POINT_SHIFT) - 1;
 154 
 155     private static final ClassValue<ConcurrentMap<NashornCallSiteDescriptor, NashornCallSiteDescriptor>> canonicals =
 156             new ClassValue<ConcurrentMap<NashornCallSiteDescriptor,NashornCallSiteDescriptor>>() {
 157         @Override
 158         protected ConcurrentMap<NashornCallSiteDescriptor, NashornCallSiteDescriptor> computeValue(final Class<?> type) {
 159             return new ConcurrentHashMap<>();
 160         }
 161     };
 162 
 163     private static final AccessControlContext GET_LOOKUP_PERMISSION_CONTEXT =
 164             AccessControlContextFactory.createAccessControlContext(CallSiteDescriptor.GET_LOOKUP_PERMISSION_NAME);
 165 
 166     @SuppressWarnings("unchecked")
 167     private static final Map<String, Reference<NamedOperation>>[] NAMED_OPERATIONS =
 168             Stream.generate(() -> Collections.synchronizedMap(new WeakHashMap<>()))
 169             .limit(OPERATIONS.length).toArray(Map[]::new);
 170 
 171     private final int flags;
 172 
 173     /**
 174      * Function used by {@link NashornTextifier} to represent call site flags in
 175      * human readable form
 176      * @param flags call site flags
 177      * @return human readable form of this callsite descriptor
 178      */
 179     public static String toString(final int flags) {
 180         final StringBuilder sb = new StringBuilder();
 181         if ((flags & CALLSITE_SCOPE) != 0) {
 182             if ((flags & CALLSITE_FAST_SCOPE) != 0) {
 183                 sb.append("fastscope ");
 184             } else {
 185                 assert (flags & CALLSITE_FAST_SCOPE) == 0 : "can't be fastscope without scope";
 186                 sb.append("scope ");
 187             }
 188             if ((flags & CALLSITE_DECLARE) != 0) {
 189                 sb.append("declare ");
 190             }
 191         }
 192         if ((flags & CALLSITE_APPLY_TO_CALL) != 0) {
 193             sb.append("apply2call ");
 194         }
 195         if ((flags & CALLSITE_STRICT) != 0) {
 196             sb.append("strict ");
 197         }
 198         return sb.length() == 0 ? "" : " " + sb.toString().trim();
 199     }
 200 
 201     /**
 202      * Given call site flags, returns the operation name encoded in them.
 203      * @param flags flags
 204      * @return the operation name
 205      */
 206     public static String getOperationName(final int flags) {
 207         switch(flags & OPERATION_MASK) {
 208         case 0: return "GET_PROPERTY";
 209         case 1: return "GET_ELEMENT";
 210         case 2: return "GET_METHOD_PROPERTY";
 211         case 3: return "GET_METHOD_ELEMENT";
 212         case 4: return "SET_PROPERTY";
 213         case 5: return "SET_ELEMENT";
 214         case 6: return "CALL";
 215         case 7: return "NEW";
 216         default: throw new AssertionError();
 217         }
 218     }
 219 
 220     /**
 221      * Retrieves a Nashorn call site descriptor with the specified values. Since call site descriptors are immutable
 222      * this method is at liberty to retrieve canonicalized instances (although it is not guaranteed it will do so).
 223      * @param lookup the lookup describing the script
 224      * @param name the name at the call site. Can not be null, but it can be empty.
 225      * @param methodType the method type at the call site
 226      * @param flags Nashorn-specific call site flags
 227      * @return a call site descriptor with the specified values.
 228      */
 229     public static NashornCallSiteDescriptor get(final MethodHandles.Lookup lookup, final String name,
 230             final MethodType methodType, final int flags) {
 231         final int opIndex = flags & OPERATION_MASK;
 232         final Operation baseOp = OPERATIONS[opIndex];
 233         final String decodedName = NameCodec.decode(name);
 234         final Operation op = decodedName.isEmpty() ? baseOp : getNamedOperation(decodedName, opIndex, baseOp);
 235         return get(lookup, op, methodType, flags);
 236     }
 237 
 238     private static NamedOperation getNamedOperation(final String name, final int opIndex, final Operation baseOp) {
 239         final Map<String, Reference<NamedOperation>> namedOps = NAMED_OPERATIONS[opIndex];
 240         final Reference<NamedOperation> ref = namedOps.get(name);
 241         if (ref != null) {
 242             final NamedOperation existing = ref.get();
 243             if (existing != null) {
 244                 return existing;
 245             }
 246         }
 247         final NamedOperation newOp = new NamedOperation(baseOp, name);
 248         namedOps.put(name, new WeakReference<>(newOp));
 249         return newOp;
 250     }
 251 
 252     private static NashornCallSiteDescriptor get(final MethodHandles.Lookup lookup, final Operation operation, final MethodType methodType, final int flags) {
 253         final NashornCallSiteDescriptor csd = new NashornCallSiteDescriptor(lookup, operation, methodType, flags);
 254         // Many of these call site descriptors are identical (e.g. every getter for a property color will be
 255         // "GET_PROPERTY:color(Object)Object", so it makes sense canonicalizing them. Make an exception for
 256         // optimistic call site descriptors, as they also carry a program point making them unique.
 257         if (csd.isOptimistic()) {
 258             return csd;
 259         }
 260         final NashornCallSiteDescriptor canonical = canonicals.get(lookup.lookupClass()).putIfAbsent(csd, csd);
 261         return canonical != null ? canonical : csd;
 262     }
 263 
 264     private NashornCallSiteDescriptor(final MethodHandles.Lookup lookup, final Operation operation, final MethodType methodType, final int flags) {
 265         super(lookup, operation, methodType);
 266         this.flags = flags;
 267     }
 268 
 269     static Lookup getLookupInternal(final CallSiteDescriptor csd) {
 270         if (csd instanceof NashornCallSiteDescriptor) {
 271             return ((NashornCallSiteDescriptor)csd).getLookupPrivileged();
 272         }
 273         return AccessController.doPrivileged((PrivilegedAction<Lookup>)()->csd.getLookup(), GET_LOOKUP_PERMISSION_CONTEXT);
 274     }
 275 
 276     @Override
 277     public boolean equals(final Object obj) {
 278         return super.equals(obj) && flags == ((NashornCallSiteDescriptor)obj).flags;
 279     }
 280 
 281     @Override
 282     public int hashCode() {
 283         return super.hashCode() ^ flags;
 284     }
 285 
 286     /**
 287      * Returns the named operand in this descriptor's operation. Equivalent to
 288      * {@code ((NamedOperation)getOperation()).getName().toString()} for call
 289      * sites with a named operand. For call sites without named operands returns null.
 290      * @return the named operand in this descriptor's operation.
 291      */
 292     public String getOperand() {
 293         return getOperand(this);
 294     }
 295 
 296     /**
 297      * Returns the named operand in the passed descriptor's operation.
 298      * Equivalent to
 299      * {@code ((NamedOperation)desc.getOperation()).getName().toString()} for
 300      * descriptors with a named operand. For descriptors without named operands
 301      * returns null.
 302      * @param desc the call site descriptors
 303      * @return the named operand in this descriptor's operation.
 304      */
 305     public static String getOperand(final CallSiteDescriptor desc) {
 306         final Operation operation = desc.getOperation();
 307         return operation instanceof NamedOperation ? ((NamedOperation)operation).getName().toString() : null;
 308     }
 309 
 310     /**
 311      * Returns the first operation in this call site descriptor's potentially
 312      * composite operation. E.g. if this call site descriptor has a composite
 313      * operation {@code GET_PROPERTY|GET_METHOD|GET_ELEM}, it will return
 314      * {@code GET_PROPERTY}. Nashorn - being a ECMAScript engine - does not
 315      * distinguish between property, element, and method namespace; ECMAScript
 316      * objects just have one single property namespace for all these, therefore
 317      * it is largely irrelevant what the composite operation is structured like;
 318      * if the first operation can't be satisfied, neither can the others. The
 319      * first operation is however sometimes used to slightly alter the
 320      * semantics; for example, a distinction between {@code GET_PROPERTY} and
 321      * {@code GET_METHOD} being the first operation can translate into whether
 322      * {@code "__noSuchProperty__"} or {@code "__noSuchMethod__"} will be
 323      * executed in case the property is not found. Note that if a call site
 324      * descriptor comes from outside of Nashorn, its class will be different,
 325      * and there is no guarantee about the way it composes its operations. For
 326      * that reason, for potentially foreign call site descriptors you should use
 327      * {@link #getFirstStandardOperation(CallSiteDescriptor)} instead.
 328      * @return the first operation in this call site descriptor. Note this will
 329      * always be a {@code StandardOperation} as Nashorn internally only uses
 330      * standard operations.
 331      */
 332     public StandardOperation getFirstOperation() {
 333         final Operation base = NamedOperation.getBaseOperation(getOperation());
 334         if (base instanceof CompositeOperation) {
 335             return (StandardOperation)((CompositeOperation)base).getOperation(0);
 336         }
 337         return (StandardOperation)base;
 338     }
 339 
 340     /**
 341      * Returns the first standard operation in the (potentially composite)
 342      * operation of the passed call site descriptor.
 343      * @param desc the call site descriptor.
 344      * @return Returns the first standard operation in the (potentially
 345      * composite) operation of the passed call site descriptor. Can return null
 346      * if the call site contains no standard operations.
 347      */
 348     public static StandardOperation getFirstStandardOperation(final CallSiteDescriptor desc) {
 349         final Operation base = NamedOperation.getBaseOperation(desc.getOperation());
 350         if (base instanceof StandardOperation) {
 351             return (StandardOperation)base;
 352         } else if (base instanceof CompositeOperation) {
 353             final CompositeOperation cop = (CompositeOperation)base;
 354             for(int i = 0; i < cop.getOperationCount(); ++i) {
 355                 final Operation op = cop.getOperation(i);
 356                 if (op instanceof StandardOperation) {
 357                     return (StandardOperation)op;
 358                 }
 359             }
 360         }
 361         return null;
 362     }
 363 
 364     /**
 365      * Returns true if the passed call site descriptor's operation contains (or
 366      * is) the specified standard operation.
 367      * @param desc the call site descriptor.
 368      * @param operation the operation whose presence is tested.
 369      * @return Returns true if the call site descriptor's operation contains (or
 370      * is) the specified standard operation.
 371      */
 372     public static boolean contains(final CallSiteDescriptor desc, final StandardOperation operation) {
 373         return CompositeOperation.contains(NamedOperation.getBaseOperation(desc.getOperation()), operation);
 374     }
 375 
 376     /**
 377      * Returns the error message to be used when CALL or NEW is used on a non-function.
 378      *
 379      * @param obj object on which CALL or NEW is used
 380      * @return error message
 381      */
 382     public String getFunctionErrorMessage(final Object obj) {
 383         final String funcDesc = getOperand();
 384         return funcDesc != null? funcDesc : ScriptRuntime.safeToString(obj);
 385     }
 386 
 387     /**
 388      * Returns the error message to be used when CALL or NEW is used on a non-function.
 389      *
 390      * @param desc call site descriptor
 391      * @param obj object on which CALL or NEW is used
 392      * @return error message
 393      */
 394     public static String getFunctionErrorMessage(final CallSiteDescriptor desc, final Object obj) {
 395         return desc instanceof NashornCallSiteDescriptor ?
 396                 ((NashornCallSiteDescriptor)desc).getFunctionErrorMessage(obj) :
 397                 ScriptRuntime.safeToString(obj);
 398     }
 399 
 400     /**
 401      * Returns the Nashorn-specific flags for this call site descriptor.
 402      * @param desc the descriptor. It can be any kind of a call site descriptor, not necessarily a
 403      * {@code NashornCallSiteDescriptor}. This allows for graceful interoperability when linking Nashorn with code
 404      * generated outside of Nashorn.
 405      * @return the Nashorn-specific flags for the call site, or 0 if the passed descriptor is not a Nashorn call site
 406      * descriptor.
 407      */
 408     public static int getFlags(final CallSiteDescriptor desc) {
 409         return desc instanceof NashornCallSiteDescriptor ? ((NashornCallSiteDescriptor)desc).flags : 0;
 410     }
 411 
 412     /**
 413      * Returns true if this descriptor has the specified flag set, see {@code CALLSITE_*} constants in this class.
 414      * @param flag the tested flag
 415      * @return true if the flag is set, false otherwise
 416      */
 417     private boolean isFlag(final int flag) {
 418         return (flags & flag) != 0;
 419     }
 420 
 421     /**
 422      * Returns true if this descriptor has the specified flag set, see {@code CALLSITE_*} constants in this class.
 423      * @param desc the descriptor. It can be any kind of a call site descriptor, not necessarily a
 424      * {@code NashornCallSiteDescriptor}. This allows for graceful interoperability when linking Nashorn with code
 425      * generated outside of Nashorn.
 426      * @param flag the tested flag
 427      * @return true if the flag is set, false otherwise (it will be false if the descriptor is not a Nashorn call site
 428      * descriptor).
 429      */
 430     private static boolean isFlag(final CallSiteDescriptor desc, final int flag) {
 431         return (getFlags(desc) & flag) != 0;
 432     }
 433 
 434     /**
 435      * Returns true if this descriptor is a Nashorn call site descriptor and has the {@link  #CALLSITE_SCOPE} flag set.
 436      * @param desc the descriptor. It can be any kind of a call site descriptor, not necessarily a
 437      * {@code NashornCallSiteDescriptor}. This allows for graceful interoperability when linking Nashorn with code
 438      * generated outside of Nashorn.
 439      * @return true if the descriptor is a Nashorn call site descriptor, and the flag is set, false otherwise.
 440      */
 441     public static boolean isScope(final CallSiteDescriptor desc) {
 442         return isFlag(desc, CALLSITE_SCOPE);
 443     }
 444 
 445     /**
 446      * Returns true if this descriptor is a Nashorn call site descriptor and has the {@link  #CALLSITE_FAST_SCOPE} flag set.
 447      * @param desc the descriptor. It can be any kind of a call site descriptor, not necessarily a
 448      * {@code NashornCallSiteDescriptor}. This allows for graceful interoperability when linking Nashorn with code
 449      * generated outside of Nashorn.
 450      * @return true if the descriptor is a Nashorn call site descriptor, and the flag is set, false otherwise.
 451      */
 452     public static boolean isFastScope(final CallSiteDescriptor desc) {
 453         return isFlag(desc, CALLSITE_FAST_SCOPE);
 454     }
 455 
 456     /**
 457      * Returns true if this descriptor is a Nashorn call site descriptor and has the {@link  #CALLSITE_STRICT} flag set.
 458      * @param desc the descriptor. It can be any kind of a call site descriptor, not necessarily a
 459      * {@code NashornCallSiteDescriptor}. This allows for graceful interoperability when linking Nashorn with code
 460      * generated outside of Nashorn.
 461      * @return true if the descriptor is a Nashorn call site descriptor, and the flag is set, false otherwise.
 462      */
 463     public static boolean isStrict(final CallSiteDescriptor desc) {
 464         return isFlag(desc, CALLSITE_STRICT);
 465     }
 466 
 467     /**
 468      * Returns true if this is an apply call that we try to call as
 469      * a "call"
 470      * @param desc descriptor
 471      * @return true if apply to call
 472      */
 473     public static boolean isApplyToCall(final CallSiteDescriptor desc) {
 474         return isFlag(desc, CALLSITE_APPLY_TO_CALL);
 475     }
 476 
 477     /**
 478      * Is this an optimistic call site
 479      * @param desc descriptor
 480      * @return true if optimistic
 481      */
 482     public static boolean isOptimistic(final CallSiteDescriptor desc) {
 483         return isFlag(desc, CALLSITE_OPTIMISTIC);
 484     }
 485 
 486     /**
 487      * Does this callsite contain a declaration for its target?
 488      * @param desc descriptor
 489      * @return true if contains declaration
 490      */
 491     public static boolean isDeclaration(final CallSiteDescriptor desc) {
 492         return isFlag(desc, CALLSITE_DECLARE);
 493     }
 494 
 495     /**
 496      * Returns true if {@code flags} has the {@link  #CALLSITE_STRICT} bit set.
 497      * @param flags the flags
 498      * @return true if the flag is set, false otherwise.
 499      */
 500     public static boolean isStrictFlag(final int flags) {
 501         return (flags & CALLSITE_STRICT) != 0;
 502     }
 503 
 504     /**
 505      * Returns true if {@code flags} has the {@link  #CALLSITE_SCOPE} bit set.
 506      * @param flags the flags
 507      * @return true if the flag is set, false otherwise.
 508      */
 509     public static boolean isScopeFlag(final int flags) {
 510         return (flags & CALLSITE_SCOPE) != 0;
 511     }
 512 
 513     /**
 514      * Get a program point from a descriptor (must be optimistic)
 515      * @param desc descriptor
 516      * @return program point
 517      */
 518     public static int getProgramPoint(final CallSiteDescriptor desc) {
 519         assert isOptimistic(desc) : "program point requested from non-optimistic descriptor " + desc;
 520         return getFlags(desc) >> CALLSITE_PROGRAM_POINT_SHIFT;
 521     }
 522 
 523     boolean isProfile() {
 524         return isFlag(CALLSITE_PROFILE);
 525     }
 526 
 527     boolean isTrace() {
 528         return isFlag(CALLSITE_TRACE);
 529     }
 530 
 531     boolean isTraceMisses() {
 532         return isFlag(CALLSITE_TRACE_MISSES);
 533     }
 534 
 535     boolean isTraceEnterExit() {
 536         return isFlag(CALLSITE_TRACE_ENTEREXIT);
 537     }
 538 
 539     boolean isTraceObjects() {
 540         return isFlag(CALLSITE_TRACE_VALUES);
 541     }
 542 
 543     boolean isOptimistic() {
 544         return isFlag(CALLSITE_OPTIMISTIC);
 545     }
 546 
 547     @Override
 548     public CallSiteDescriptor changeMethodTypeInternal(final MethodType newMethodType) {
 549         return get(getLookupPrivileged(), getOperation(), newMethodType, flags);
 550     }
 551 }