@@ -313,10 +313,21 @@ protected AnalysisMethod(AnalysisMethod original, MultiMethodKey multiMethodKey)
313313 this .enableReachableInCurrentLayer = original .enableReachableInCurrentLayer ;
314314 }
315315
316+ /**
317+ * This method should not be used directly, except to set the {@link CompilationBehavior} from a
318+ * previous layer. To set a new {@link CompilationBehavior}, please use the associated setter.
319+ */
316320 public void setCompilationBehavior (CompilationBehavior compilationBehavior ) {
321+ assert getUniverse ().getBigbang ().getHostVM ().buildingImageLayer () : "The method compilation behavior can only be set in layered images" ;
317322 this .compilationBehavior = compilationBehavior ;
318323 }
319324
325+ private void setNewCompilationBehavior (CompilationBehavior compilationBehavior ) {
326+ assert (!isInBaseLayer && this .compilationBehavior == CompilationBehavior .DEFAULT ) || this .compilationBehavior == compilationBehavior : "The method was already assigned " +
327+ this .compilationBehavior + ", but trying to assign " + compilationBehavior ;
328+ setCompilationBehavior (compilationBehavior );
329+ }
330+
320331 public CompilationBehavior getCompilationBehavior () {
321332 return compilationBehavior ;
322333 }
@@ -327,11 +338,11 @@ public CompilationBehavior getCompilationBehavior() {
327338 */
328339 public void setFullyDelayedToApplicationLayer () {
329340 HostVM hostVM = getUniverse ().getBigbang ().getHostVM ();
330- AnalysisError .guarantee (hostVM .buildingImageLayer (), "Methods can only be delayed in layered images" );
341+ AnalysisError .guarantee (hostVM .buildingImageLayer (), "Methods can only be delayed in layered images: %s" , this );
331342 AnalysisError .guarantee (parsedGraphCacheState .get () == GraphCacheEntry .UNPARSED , "The method %s was marked as delayed to the application layer but was already parsed" , this );
332343 AnalysisError .guarantee (!hostVM .hasAlwaysInlineDirective (this ), "Method %s with an always inline directive cannot be delayed to the application layer as such methods cannot be inlined" , this );
333344 AnalysisError .guarantee (isConcrete (), "Method %s is not concrete and cannot be delayed to the application layer" , this );
334- this . compilationBehavior = CompilationBehavior .FULLY_DELAYED_TO_APPLICATION_LAYER ;
345+ setNewCompilationBehavior ( CompilationBehavior .FULLY_DELAYED_TO_APPLICATION_LAYER ) ;
335346 }
336347
337348 /**
@@ -342,6 +353,22 @@ public boolean isDelayed() {
342353 return compilationBehavior == CompilationBehavior .FULLY_DELAYED_TO_APPLICATION_LAYER && buildingSharedLayer ;
343354 }
344355
356+ public void setPinnedToInitialLayer () {
357+ BigBang bigbang = getUniverse ().getBigbang ();
358+ AnalysisError .guarantee (bigbang .getHostVM ().buildingInitialLayer (), "Methods can only be pinned to the initial layer: %s" , this );
359+ boolean nonAbstractInstanceClass = !declaringClass .isArray () && declaringClass .isInstanceClass () && !declaringClass .isAbstract ();
360+ AnalysisError .guarantee (nonAbstractInstanceClass , "Only methods from non abstract instance class can be delayed: %s" , this );
361+ bigbang .forcedAddRootMethod (this , true , "Method is pinned to the initial layer" );
362+ if (!isStatic ()) {
363+ declaringClass .registerAsInstantiated (this + " is pinned to the initial layer" );
364+ }
365+ setNewCompilationBehavior (CompilationBehavior .PINNED_TO_INITIAL_LAYER );
366+ }
367+
368+ public boolean isPinnedToInitialLayer () {
369+ return compilationBehavior == CompilationBehavior .PINNED_TO_INITIAL_LAYER ;
370+ }
371+
345372 private static String createName (ResolvedJavaMethod wrapped , MultiMethodKey multiMethodKey ) {
346373 String aName = wrapped .getName ();
347374 if (multiMethodKey != ORIGINAL_METHOD ) {
@@ -1429,9 +1456,9 @@ public enum CompilationBehavior {
14291456 DEFAULT ,
14301457
14311458 /**
1432- * Method is pinned to a specific shared layer, meaning it has to be analyzed and compiled
1433- * in this specific layer. A method can only be pinned to a shared layer.
1459+ * Method is pinned to the initial layer, meaning it has to be analyzed and compiled in this
1460+ * specific layer.
14341461 */
1435- PINNED_TO_SHARED_LAYER ,
1462+ PINNED_TO_INITIAL_LAYER ,
14361463 }
14371464}
0 commit comments