1 /* 2 * Copyright (c) 2015, 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. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 package org.graalvm.compiler.nodes.graphbuilderconf; 24 25 import org.graalvm.compiler.nodes.ValueNode; 26 27 import jdk.vm.ci.meta.JavaKind; 28 import jdk.vm.ci.meta.JavaTypeProfile; 29 import jdk.vm.ci.meta.ResolvedJavaField; 30 import jdk.vm.ci.meta.ResolvedJavaMethod; 31 import jdk.vm.ci.meta.ResolvedJavaType; 32 import jdk.vm.ci.meta.Signature; 33 34 public interface NodePlugin extends GraphBuilderPlugin { 35 /** 36 * Handle the parsing of a method invocation bytecode to a method that can be bound statically. 37 * If the method returns true, it must {@link GraphBuilderContext#push push} a value as the 38 * result of the method invocation using the {@link Signature#getReturnKind return kind} of the 39 * method. 40 * 41 * @param b the context 42 * @param method the statically bound, invoked method 43 * @param args the arguments of the method invocation 44 * @return true if the plugin handles the invocation, false otherwise 45 */ 46 default boolean handleInvoke(GraphBuilderContext b, ResolvedJavaMethod method, ValueNode[] args) { 47 return false; 48 } 49 50 /** 51 * Handle the parsing of a GETFIELD bytecode. If the method returns true, it must 52 * {@link GraphBuilderContext#push push} a value using the 53 * {@link ResolvedJavaField#getJavaKind() kind} of the field. 54 * 55 * @param b the context 56 * @param object the receiver object for the field access 57 * @param field the accessed field 58 * @return true if the plugin handles the field access, false otherwise 59 */ 60 default boolean handleLoadField(GraphBuilderContext b, ValueNode object, ResolvedJavaField field) { 61 return false; 62 } 63 64 /** 65 * Handle the parsing of a GETSTATIC bytecode. If the method returns true, it must 66 * {@link GraphBuilderContext#push push} a value using the 67 * {@link ResolvedJavaField#getJavaKind() kind} of the field. 68 * 69 * @param b the context 70 * @param field the accessed field 71 * @return true if the plugin handles the field access, false otherwise 72 */ 73 default boolean handleLoadStaticField(GraphBuilderContext b, ResolvedJavaField field) { 74 return false; 75 } 76 77 /** 78 * Handle the parsing of a PUTFIELD bytecode. 79 * 80 * @param b the context 81 * @param object the receiver object for the field access 82 * @param field the accessed field 83 * @param value the value to be stored into the field 84 * @return true if the plugin handles the field access, false otherwise 85 */ 86 default boolean handleStoreField(GraphBuilderContext b, ValueNode object, ResolvedJavaField field, ValueNode value) { 87 return false; 88 } 89 90 /** 91 * Handle the parsing of a PUTSTATIC bytecode. 92 * 93 * @param b the context 94 * @param field the accessed field 95 * @param value the value to be stored into the field 96 * @return true if the plugin handles the field access, false otherwise. 97 */ 98 default boolean handleStoreStaticField(GraphBuilderContext b, ResolvedJavaField field, ValueNode value) { 99 return false; 100 } 101 102 /** 103 * Handle the parsing of an array load bytecode. If the method returns true, it must 104 * {@link GraphBuilderContext#push push} a value using the provided elementKind. 105 * 106 * @param b the context 107 * @param array the accessed array 108 * @param index the index for the array access 109 * @param elementKind the element kind of the accessed array 110 * @return true if the plugin handles the array access, false otherwise. 111 */ 112 default boolean handleLoadIndexed(GraphBuilderContext b, ValueNode array, ValueNode index, JavaKind elementKind) { 113 return false; 114 } 115 116 /** 117 * Handle the parsing of an array store bytecode. 118 * 119 * @param b the context 120 * @param array the accessed array 121 * @param index the index for the array access 122 * @param elementKind the element kind of the accessed array 123 * @param value the value to be stored into the array 124 * @return true if the plugin handles the array access, false otherwise. 125 */ 126 default boolean handleStoreIndexed(GraphBuilderContext b, ValueNode array, ValueNode index, JavaKind elementKind, ValueNode value) { 127 return false; 128 } 129 130 /** 131 * Handle the parsing of a CHECKCAST bytecode. If the method returns true, it must 132 * {@link GraphBuilderContext#push push} a value with the result of the cast using 133 * {@link JavaKind#Object}. 134 * 135 * @param b the context 136 * @param object the object to be type checked 137 * @param type the type that the object is checked against 138 * @param profile the profiling information for the type check, or null if no profiling 139 * information is available 140 * @return true if the plugin handles the cast, false otherwise 141 */ 142 default boolean handleCheckCast(GraphBuilderContext b, ValueNode object, ResolvedJavaType type, JavaTypeProfile profile) { 143 return false; 144 } 145 146 /** 147 * Handle the parsing of a INSTANCEOF bytecode. If the method returns true, it must 148 * {@link GraphBuilderContext#push push} a value with the result of the instanceof using 149 * {@link JavaKind#Int}. 150 * 151 * @param b the context 152 * @param object the object to be type checked 153 * @param type the type that the object is checked against 154 * @param profile the profiling information for the type check, or null if no profiling 155 * information is available 156 * @return true if the plugin handles the instanceof, false otherwise 157 */ 158 default boolean handleInstanceOf(GraphBuilderContext b, ValueNode object, ResolvedJavaType type, JavaTypeProfile profile) { 159 return false; 160 } 161 162 /** 163 * Handle the parsing of a NEW bytecode. If the method returns true, it must 164 * {@link GraphBuilderContext#push push} a value with the result of the allocation using 165 * {@link JavaKind#Object}. 166 * 167 * @param b the context 168 * @param type the type to be instantiated 169 * @return true if the plugin handles the bytecode, false otherwise 170 */ 171 default boolean handleNewInstance(GraphBuilderContext b, ResolvedJavaType type) { 172 return false; 173 } 174 175 /** 176 * Handle the parsing of a NEWARRAY and ANEWARRAY bytecode. If the method returns true, it must 177 * {@link GraphBuilderContext#push push} a value with the result of the allocation using 178 * {@link JavaKind#Object}. 179 * 180 * @param b the context 181 * @param elementType the element type of the array to be instantiated 182 * @param length the length of the new array 183 * @return true if the plugin handles the bytecode, false otherwise 184 */ 185 default boolean handleNewArray(GraphBuilderContext b, ResolvedJavaType elementType, ValueNode length) { 186 return false; 187 } 188 189 /** 190 * Handle the parsing of a MULTIANEWARRAY bytecode. If the method returns true, it must 191 * {@link GraphBuilderContext#push push} a value with the result of the allocation using 192 * {@link JavaKind#Object}. 193 * 194 * @param b the context 195 * @param type the type of the outermost array to be instantiated 196 * @param dimensions the array of lengths for all the dimensions to be instantiated 197 * @return true if the plugin handles the bytecode, false otherwise 198 */ 199 default boolean handleNewMultiArray(GraphBuilderContext b, ResolvedJavaType type, ValueNode[] dimensions) { 200 return false; 201 } 202 203 /** 204 * If the plugin {@link GraphBuilderContext#push pushes} a value with a different 205 * {@link JavaKind} than specified by the bytecode, it must override this method and return 206 * {@code true}. This disables assertion checking for value kinds. 207 * 208 * @param b the context 209 */ 210 default boolean canChangeStackKind(GraphBuilderContext b) { 211 return false; 212 } 213 }