49 * through the JVM state since intrinsics can employ non-Java kinds to represent values such as raw 50 * machine words and pointers. 51 */ 52 public class IntrinsicContext { 53 54 /** 55 * Method being intrinsified. 56 */ 57 final ResolvedJavaMethod method; 58 59 /** 60 * Method providing the intrinsic implementation. 61 */ 62 final ResolvedJavaMethod intrinsic; 63 64 /** 65 * Provider of bytecode to be parsed for a method that is part of an intrinsic. 66 */ 67 final BytecodeProvider bytecodeProvider; 68 69 /** 70 * Gets the method being intrinsified. 71 */ 72 public ResolvedJavaMethod getOriginalMethod() { 73 return method; 74 } 75 76 /** 77 * Gets the method providing the intrinsic implementation. 78 */ 79 public ResolvedJavaMethod getIntrinsicMethod() { 80 return intrinsic; 81 } 82 83 /** 84 * Gets provider of bytecode to be parsed for a method that is part of an intrinsic. 85 */ 86 public BytecodeProvider getBytecodeProvider() { 87 return bytecodeProvider; 88 } 89 90 /** 91 * Determines if a call within the compilation scope of this intrinsic represents a call to the 92 * {@linkplain #getOriginalMethod() original} method. This denotes the path where a partial 93 * intrinsification falls back to the original method. 94 */ 95 public boolean isCallToOriginal(ResolvedJavaMethod targetMethod) { 96 return method.equals(targetMethod) || intrinsic.equals(targetMethod); 97 } 98 99 final CompilationContext compilationContext; 100 101 public IntrinsicContext(ResolvedJavaMethod method, ResolvedJavaMethod intrinsic, BytecodeProvider bytecodeProvider, CompilationContext compilationContext) { 102 this.method = method; 103 this.intrinsic = intrinsic; 104 this.bytecodeProvider = bytecodeProvider; 105 assert bytecodeProvider != null; 106 this.compilationContext = compilationContext; 107 assert !isCompilationRoot() || method.hasBytecodes() : "Cannot root compile intrinsic for native or abstract method " + method.format("%H.%n(%p)"); 108 } 109 110 public boolean isPostParseInlined() { 111 return compilationContext.equals(INLINE_AFTER_PARSING); 112 } 113 114 public boolean isCompilationRoot() { 115 return compilationContext.equals(ROOT_COMPILATION); 116 } 117 118 /** 119 * Denotes the compilation context in which an intrinsic is being parsed. 120 */ 121 public enum CompilationContext { 122 /** 123 * An intrinsic is being processed when parsing an invoke bytecode that calls the 124 * intrinsified method. 125 */ 126 INLINE_DURING_PARSING, 127 | 49 * through the JVM state since intrinsics can employ non-Java kinds to represent values such as raw 50 * machine words and pointers. 51 */ 52 public class IntrinsicContext { 53 54 /** 55 * Method being intrinsified. 56 */ 57 final ResolvedJavaMethod method; 58 59 /** 60 * Method providing the intrinsic implementation. 61 */ 62 final ResolvedJavaMethod intrinsic; 63 64 /** 65 * Provider of bytecode to be parsed for a method that is part of an intrinsic. 66 */ 67 final BytecodeProvider bytecodeProvider; 68 69 final CompilationContext compilationContext; 70 71 final boolean allowPartialIntrinsicArgumentMismatch; 72 73 public IntrinsicContext(ResolvedJavaMethod method, ResolvedJavaMethod intrinsic, BytecodeProvider bytecodeProvider, CompilationContext compilationContext) { 74 this(method, intrinsic, bytecodeProvider, compilationContext, false); 75 } 76 77 public IntrinsicContext(ResolvedJavaMethod method, ResolvedJavaMethod intrinsic, BytecodeProvider bytecodeProvider, CompilationContext compilationContext, 78 boolean allowPartialIntrinsicArgumentMismatch) { 79 this.method = method; 80 this.intrinsic = intrinsic; 81 this.bytecodeProvider = bytecodeProvider; 82 assert bytecodeProvider != null; 83 this.compilationContext = compilationContext; 84 this.allowPartialIntrinsicArgumentMismatch = allowPartialIntrinsicArgumentMismatch; 85 assert !isCompilationRoot() || method.hasBytecodes() : "Cannot root compile intrinsic for native or abstract method " + method.format("%H.%n(%p)"); 86 } 87 88 /** 89 * A partial intrinsic exits by (effectively) calling the intrinsified method. Normally, this 90 * call must use exactly the same arguments as the call that is being intrinsified. This allows 91 * to override this behavior. 92 */ 93 public boolean allowPartialIntrinsicArgumentMismatch() { 94 return allowPartialIntrinsicArgumentMismatch; 95 } 96 97 /** 98 * Gets the method being intrinsified. 99 */ 100 public ResolvedJavaMethod getOriginalMethod() { 101 return method; 102 } 103 104 /** 105 * Gets the method providing the intrinsic implementation. 106 */ 107 public ResolvedJavaMethod getIntrinsicMethod() { 108 return intrinsic; 109 } 110 111 /** 112 * Gets provider of bytecode to be parsed for a method that is part of an intrinsic. 113 */ 114 public BytecodeProvider getBytecodeProvider() { 115 return bytecodeProvider; 116 } 117 118 /** 119 * Determines if a call within the compilation scope of this intrinsic represents a call to the 120 * {@linkplain #getOriginalMethod() original} method. This denotes the path where a partial 121 * intrinsification falls back to the original method. 122 */ 123 public boolean isCallToOriginal(ResolvedJavaMethod targetMethod) { 124 return method.equals(targetMethod) || intrinsic.equals(targetMethod); 125 } 126 127 public boolean isPostParseInlined() { 128 return compilationContext.equals(INLINE_AFTER_PARSING); 129 } 130 131 public boolean isCompilationRoot() { 132 return compilationContext.equals(ROOT_COMPILATION); 133 } 134 135 /** 136 * Denotes the compilation context in which an intrinsic is being parsed. 137 */ 138 public enum CompilationContext { 139 /** 140 * An intrinsic is being processed when parsing an invoke bytecode that calls the 141 * intrinsified method. 142 */ 143 INLINE_DURING_PARSING, 144 |