1 /* 2 * Copyright (c) 2004, 2018, 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 24 #ifndef _NSK_SHARE_JVMTI_INJECTOR_H_ 25 #define _NSK_SHARE_JVMTI_INJECTOR_H_ 26 27 /* Class File Format Constants 28 */ 29 30 typedef unsigned char u1; 31 typedef unsigned short u2; 32 typedef unsigned int u4; 33 34 /* Constant table */ 35 enum { 36 CONSTANT_Utf8 = 1, 37 CONSTANT_Integer = 3, 38 CONSTANT_Float = 4, 39 CONSTANT_Long = 5, 40 CONSTANT_Double = 6, 41 CONSTANT_Class = 7, 42 CONSTANT_String = 8, 43 CONSTANT_Fieldref = 9, 44 CONSTANT_Methodref = 10, 45 CONSTANT_InterfaceMethodref = 11, 46 CONSTANT_NameAndType = 12, 47 CONSTANT_MethodHandle = 15, 48 CONSTANT_MethodType = 16, 49 CONSTANT_InvokeDynamic = 18 50 }; 51 52 /* Access and modifier flags */ 53 enum { 54 ACC_PUBLIC = 0x00000001, 55 ACC_PRIVATE = 0x00000002, 56 ACC_PROTECTED = 0x00000004, 57 ACC_STATIC = 0x00000008, 58 ACC_FINAL = 0x00000010, 59 ACC_SYNCHRONIZED = 0x00000020, 60 ACC_VOLATILE = 0x00000040, 61 ACC_TRANSIENT = 0x00000080, 62 ACC_NATIVE = 0x00000100, 63 ACC_INTERFACE = 0x00000200, 64 ACC_ABSTRACT = 0x00000400, 65 ACC_SUPER = 0x00000020, 66 ACC_STRICT = 0x00000800 67 }; 68 69 /* Opcodes */ 70 enum { 71 opc_nop = 0, 72 opc_aconst_null = 1, 73 opc_iconst_m1 = 2, 74 opc_iconst_0 = 3, 75 opc_iconst_1 = 4, 76 opc_iconst_2 = 5, 77 opc_iconst_3 = 6, 78 opc_iconst_4 = 7, 79 opc_iconst_5 = 8, 80 opc_lconst_0 = 9, 81 opc_lconst_1 = 10, 82 opc_fconst_0 = 11, 83 opc_fconst_1 = 12, 84 opc_fconst_2 = 13, 85 opc_dconst_0 = 14, 86 opc_dconst_1 = 15, 87 opc_bipush = 16, 88 opc_sipush = 17, 89 opc_ldc = 18, 90 opc_ldc_w = 19, 91 opc_ldc2_w = 20, 92 opc_iload = 21, 93 opc_lload = 22, 94 opc_fload = 23, 95 opc_dload = 24, 96 opc_aload = 25, 97 opc_iload_0 = 26, 98 opc_iload_1 = 27, 99 opc_iload_2 = 28, 100 opc_iload_3 = 29, 101 opc_lload_0 = 30, 102 opc_lload_1 = 31, 103 opc_lload_2 = 32, 104 opc_lload_3 = 33, 105 opc_fload_0 = 34, 106 opc_fload_1 = 35, 107 opc_fload_2 = 36, 108 opc_fload_3 = 37, 109 opc_dload_0 = 38, 110 opc_dload_1 = 39, 111 opc_dload_2 = 40, 112 opc_dload_3 = 41, 113 opc_aload_0 = 42, 114 opc_aload_1 = 43, 115 opc_aload_2 = 44, 116 opc_aload_3 = 45, 117 opc_iaload = 46, 118 opc_laload = 47, 119 opc_faload = 48, 120 opc_daload = 49, 121 opc_aaload = 50, 122 opc_baload = 51, 123 opc_caload = 52, 124 opc_saload = 53, 125 opc_istore = 54, 126 opc_lstore = 55, 127 opc_fstore = 56, 128 opc_dstore = 57, 129 opc_astore = 58, 130 opc_istore_0 = 59, 131 opc_istore_1 = 60, 132 opc_istore_2 = 61, 133 opc_istore_3 = 62, 134 opc_lstore_0 = 63, 135 opc_lstore_1 = 64, 136 opc_lstore_2 = 65, 137 opc_lstore_3 = 66, 138 opc_fstore_0 = 67, 139 opc_fstore_1 = 68, 140 opc_fstore_2 = 69, 141 opc_fstore_3 = 70, 142 opc_dstore_0 = 71, 143 opc_dstore_1 = 72, 144 opc_dstore_2 = 73, 145 opc_dstore_3 = 74, 146 opc_astore_0 = 75, 147 opc_astore_1 = 76, 148 opc_astore_2 = 77, 149 opc_astore_3 = 78, 150 opc_iastore = 79, 151 opc_lastore = 80, 152 opc_fastore = 81, 153 opc_dastore = 82, 154 opc_aastore = 83, 155 opc_bastore = 84, 156 opc_castore = 85, 157 opc_sastore = 86, 158 opc_pop = 87, 159 opc_pop2 = 88, 160 opc_dup = 89, 161 opc_dup_x1 = 90, 162 opc_dup_x2 = 91, 163 opc_dup2 = 92, 164 opc_dup2_x1 = 93, 165 opc_dup2_x2 = 94, 166 opc_swap = 95, 167 opc_iadd = 96, 168 opc_ladd = 97, 169 opc_fadd = 98, 170 opc_dadd = 99, 171 opc_isub = 100, 172 opc_lsub = 101, 173 opc_fsub = 102, 174 opc_dsub = 103, 175 opc_imul = 104, 176 opc_lmul = 105, 177 opc_fmul = 106, 178 opc_dmul = 107, 179 opc_idiv = 108, 180 opc_ldiv = 109, 181 opc_fdiv = 110, 182 opc_ddiv = 111, 183 opc_irem = 112, 184 opc_lrem = 113, 185 opc_frem = 114, 186 opc_drem = 115, 187 opc_ineg = 116, 188 opc_lneg = 117, 189 opc_fneg = 118, 190 opc_dneg = 119, 191 opc_ishl = 120, 192 opc_lshl = 121, 193 opc_ishr = 122, 194 opc_lshr = 123, 195 opc_iushr = 124, 196 opc_lushr = 125, 197 opc_iand = 126, 198 opc_land = 127, 199 opc_ior = 128, 200 opc_lor = 129, 201 opc_ixor = 130, 202 opc_lxor = 131, 203 opc_iinc = 132, 204 opc_i2l = 133, 205 opc_i2f = 134, 206 opc_i2d = 135, 207 opc_l2i = 136, 208 opc_l2f = 137, 209 opc_l2d = 138, 210 opc_f2i = 139, 211 opc_f2l = 140, 212 opc_f2d = 141, 213 opc_d2i = 142, 214 opc_d2l = 143, 215 opc_d2f = 144, 216 opc_i2b = 145, 217 opc_i2c = 146, 218 opc_i2s = 147, 219 opc_lcmp = 148, 220 opc_fcmpl = 149, 221 opc_fcmpg = 150, 222 opc_dcmpl = 151, 223 opc_dcmpg = 152, 224 opc_ifeq = 153, 225 opc_ifne = 154, 226 opc_iflt = 155, 227 opc_ifge = 156, 228 opc_ifgt = 157, 229 opc_ifle = 158, 230 opc_if_icmpeq = 159, 231 opc_if_icmpne = 160, 232 opc_if_icmplt = 161, 233 opc_if_icmpge = 162, 234 opc_if_icmpgt = 163, 235 opc_if_icmple = 164, 236 opc_if_acmpeq = 165, 237 opc_if_acmpne = 166, 238 opc_goto = 167, 239 opc_jsr = 168, 240 opc_ret = 169, 241 opc_tableswitch = 170, 242 opc_lookupswitch = 171, 243 opc_ireturn = 172, 244 opc_lreturn = 173, 245 opc_freturn = 174, 246 opc_dreturn = 175, 247 opc_areturn = 176, 248 opc_return = 177, 249 opc_getstatic = 178, 250 opc_putstatic = 179, 251 opc_getfield = 180, 252 opc_putfield = 181, 253 opc_invokevirtual = 182, 254 opc_invokespecial = 183, 255 opc_invokestatic = 184, 256 opc_invokeinterface = 185, 257 opc_invokedynamic = 186, 258 opc_new = 187, 259 opc_newarray = 188, 260 opc_anewarray = 189, 261 opc_arraylength = 190, 262 opc_athrow = 191, 263 opc_checkcast = 192, 264 opc_instanceof = 193, 265 opc_monitorenter = 194, 266 opc_monitorexit = 195, 267 opc_wide = 196, 268 opc_multianewarray = 197, 269 opc_ifnull = 198, 270 opc_ifnonnull = 199, 271 opc_goto_w = 200, 272 opc_jsr_w = 201, 273 opc_breakpoint = 202 274 }; 275 276 enum { 277 BCI_MODE_EMCP = 0, 278 BCI_MODE_CALL = 1, 279 BCI_MODE_ALLOC = 2 280 }; 281 282 #ifdef __cplusplus 283 extern "C" { 284 #endif 285 286 /** 287 * Class file transformer. Transforms a classfile image from old_bytes 288 * to a new classfile image new_bytes according to value of bci_mode. 289 * The new classfile image is allocated with malloc(), and should be 290 * freed by the caller. The possible bci_mode values: 291 * 292 * BCI_MODE_EMCP 293 * dummy, without injection any bytecodes 294 * 295 * BCI_MODE_CALL 296 * inject invokestatic call to ProfileCollector.callTracker() 297 * at the beginning of all methods 298 * 299 * BCI_MODE_ALLOC 300 * inject invokestatic call to ProfileCollector.allocTracker() 301 * immediately following new/newarray opcodes. 302 * 303 */ 304 305 int Inject(const u1* old_bytes, const jint old_length, 306 u1** new_bytes, jint* new_length, int bci_mode); 307 308 #ifdef __cplusplus 309 } 310 #endif 311 312 #endif /* _NSK_SHARE_JVMTI_INJECTOR_H_ */