< prev index next >

src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/RecompilableScriptFunctionData.java

Print this page




  83     public static final String RECOMPILATION_PREFIX = "Recompilation$";
  84 
  85     private static final ExecutorService astSerializerExecutorService = createAstSerializerExecutorService();
  86 
  87     /** Unique function node id for this function node */
  88     private final int functionNodeId;
  89 
  90     private final String functionName;
  91 
  92     /** The line number where this function begins. */
  93     private final int lineNumber;
  94 
  95     /** Source from which FunctionNode was parsed. */
  96     private transient Source source;
  97 
  98     /**
  99      * Cached form of the AST. Either a {@code SerializedAst} object used by split functions as they can't be
 100      * reparsed from source, or a soft reference to a {@code FunctionNode} for other functions (it is safe
 101      * to be cleared as they can be reparsed).
 102      */
 103     private volatile Object cachedAst;
 104 
 105     /** Token of this function within the source. */
 106     private final long token;
 107 
 108     /**
 109      * Represents the allocation strategy (property map, script object class, and method handle) for when
 110      * this function is used as a constructor. Note that majority of functions (those not setting any this.*
 111      * properties) will share a single canonical "default strategy" instance.
 112      */
 113     private final AllocationStrategy allocationStrategy;
 114 
 115     /**
 116      * Opaque object representing parser state at the end of the function. Used when reparsing outer function
 117      * to help with skipping parsing inner functions.
 118      */
 119     private final Object endParserState;
 120 
 121     /** Code installer used for all further recompilation/specialization of this ScriptFunction */
 122     private transient CodeInstaller installer;
 123 


 272 
 273     @Override
 274     String toSource() {
 275         if (source != null && token != 0) {
 276             return source.getString(Token.descPosition(token), Token.descLength(token));
 277         }
 278 
 279         return "function " + (name == null ? "" : name) + "() { [native code] }";
 280     }
 281 
 282     /**
 283      * Initialize transient fields on deserialized instances
 284      *
 285      * @param src source
 286      * @param inst code installer
 287      */
 288     public void initTransients(final Source src, final CodeInstaller inst) {
 289         if (this.source == null && this.installer == null) {
 290             this.source    = src;
 291             this.installer = inst;



 292         } else if (this.source != src || !this.installer.isCompatibleWith(inst)) {
 293             // Existing values must be same as those passed as parameters
 294             throw new IllegalArgumentException();
 295         }
 296     }
 297 
 298     @Override
 299     public String toString() {
 300         return super.toString() + '@' + functionNodeId;
 301     }
 302 
 303     @Override
 304     public String toStringVerbose() {
 305         final StringBuilder sb = new StringBuilder();
 306 
 307         sb.append("fnId=").append(functionNodeId).append(' ');
 308 
 309         if (source != null) {
 310             sb.append(source.getName())
 311                 .append(':')




  83     public static final String RECOMPILATION_PREFIX = "Recompilation$";
  84 
  85     private static final ExecutorService astSerializerExecutorService = createAstSerializerExecutorService();
  86 
  87     /** Unique function node id for this function node */
  88     private final int functionNodeId;
  89 
  90     private final String functionName;
  91 
  92     /** The line number where this function begins. */
  93     private final int lineNumber;
  94 
  95     /** Source from which FunctionNode was parsed. */
  96     private transient Source source;
  97 
  98     /**
  99      * Cached form of the AST. Either a {@code SerializedAst} object used by split functions as they can't be
 100      * reparsed from source, or a soft reference to a {@code FunctionNode} for other functions (it is safe
 101      * to be cleared as they can be reparsed).
 102      */
 103     private volatile transient Object cachedAst;
 104 
 105     /** Token of this function within the source. */
 106     private final long token;
 107 
 108     /**
 109      * Represents the allocation strategy (property map, script object class, and method handle) for when
 110      * this function is used as a constructor. Note that majority of functions (those not setting any this.*
 111      * properties) will share a single canonical "default strategy" instance.
 112      */
 113     private final AllocationStrategy allocationStrategy;
 114 
 115     /**
 116      * Opaque object representing parser state at the end of the function. Used when reparsing outer function
 117      * to help with skipping parsing inner functions.
 118      */
 119     private final Object endParserState;
 120 
 121     /** Code installer used for all further recompilation/specialization of this ScriptFunction */
 122     private transient CodeInstaller installer;
 123 


 272 
 273     @Override
 274     String toSource() {
 275         if (source != null && token != 0) {
 276             return source.getString(Token.descPosition(token), Token.descLength(token));
 277         }
 278 
 279         return "function " + (name == null ? "" : name) + "() { [native code] }";
 280     }
 281 
 282     /**
 283      * Initialize transient fields on deserialized instances
 284      *
 285      * @param src source
 286      * @param inst code installer
 287      */
 288     public void initTransients(final Source src, final CodeInstaller inst) {
 289         if (this.source == null && this.installer == null) {
 290             this.source    = src;
 291             this.installer = inst;
 292             for (final RecompilableScriptFunctionData nested : nestedFunctions.values()) {
 293                 nested.initTransients(src, inst);
 294             }
 295         } else if (this.source != src || !this.installer.isCompatibleWith(inst)) {
 296             // Existing values must be same as those passed as parameters
 297             throw new IllegalArgumentException();
 298         }
 299     }
 300 
 301     @Override
 302     public String toString() {
 303         return super.toString() + '@' + functionNodeId;
 304     }
 305 
 306     @Override
 307     public String toStringVerbose() {
 308         final StringBuilder sb = new StringBuilder();
 309 
 310         sb.append("fnId=").append(functionNodeId).append(' ');
 311 
 312         if (source != null) {
 313             sb.append(source.getName())
 314                 .append(':')


< prev index next >