1 /* 2 * Copyright (c) 1997, 2010, 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 25 #ifndef CC_INTERP 26 // All the necessary definitions used for (bytecode) template generation. Instead of 27 // spreading the implementation functionality for each bytecode in the interpreter 28 // and the snippet generator, a template is assigned to each bytecode which can be 29 // used to generate the bytecode's implementation if needed. 30 31 32 // A Template describes the properties of a code template for a given bytecode 33 // and provides a generator to generate the code template. 34 35 class Template VALUE_OBJ_CLASS_SPEC { 36 private: 37 enum Flags { 38 uses_bcp_bit, // set if template needs the bcp pointing to bytecode 39 does_dispatch_bit, // set if template dispatches on its own 40 calls_vm_bit, // set if template calls the vm 41 wide_bit // set if template belongs to a wide instruction 42 }; 43 44 typedef void (*generator)(int arg); 45 46 int _flags; // describes interpreter template properties (bcp unknown) 47 TosState _tos_in; // tos cache state before template execution 48 TosState _tos_out; // tos cache state after template execution 49 generator _gen; // template code generator 50 int _arg; // argument for template code generator 51 52 void initialize(int flags, TosState tos_in, TosState tos_out, generator gen, int arg); 53 54 friend class TemplateTable; 55 56 public: 57 Bytecodes::Code bytecode() const; 58 bool is_valid() const { return _gen != NULL; } 59 bool uses_bcp() const { return (_flags & (1 << uses_bcp_bit )) != 0; } 60 bool does_dispatch() const { return (_flags & (1 << does_dispatch_bit)) != 0; } 61 bool calls_vm() const { return (_flags & (1 << calls_vm_bit )) != 0; } 62 bool is_wide() const { return (_flags & (1 << wide_bit )) != 0; } 63 TosState tos_in() const { return _tos_in; } 64 TosState tos_out() const { return _tos_out; } 65 void generate(InterpreterMacroAssembler* masm); 66 }; 67 68 69 // The TemplateTable defines all Templates and provides accessor functions 70 // to get the template for a given bytecode. 71 72 class TemplateTable: AllStatic { 73 public: 74 enum Operation { add, sub, mul, div, rem, _and, _or, _xor, shl, shr, ushr }; 75 enum Condition { equal, not_equal, less, less_equal, greater, greater_equal }; 76 enum CacheByte { f1_byte = 1, f2_byte = 2, f1_oop = 0x11 }; // byte_no codes 77 78 private: 79 static bool _is_initialized; // true if TemplateTable has been initialized 80 static Template _template_table [Bytecodes::number_of_codes]; 81 static Template _template_table_wide[Bytecodes::number_of_codes]; 82 83 static Template* _desc; // the current template to be generated 84 static Bytecodes::Code bytecode() { return _desc->bytecode(); } 85 86 static BarrierSet* _bs; // Cache the barrier set. 87 public: 88 //%note templates_1 89 static InterpreterMacroAssembler* _masm; // the assembler used when generating templates 90 91 private: 92 93 // special registers 94 static inline Address at_bcp(int offset); 95 96 // helpers 97 static void unimplemented_bc(); 98 static void patch_bytecode(Bytecodes::Code bc, Register scratch1, 99 Register scratch2, bool load_bc_in_scratch = true); 100 101 // C calls 102 static void call_VM(Register oop_result, address entry_point); 103 static void call_VM(Register oop_result, address entry_point, Register arg_1); 104 static void call_VM(Register oop_result, address entry_point, Register arg_1, Register arg_2); 105 static void call_VM(Register oop_result, address entry_point, Register arg_1, Register arg_2, Register arg_3); 106 107 // these overloadings are not presently used on SPARC: 108 static void call_VM(Register oop_result, Register last_java_sp, address entry_point); 109 static void call_VM(Register oop_result, Register last_java_sp, address entry_point, Register arg_1); 110 static void call_VM(Register oop_result, Register last_java_sp, address entry_point, Register arg_1, Register arg_2); 111 static void call_VM(Register oop_result, Register last_java_sp, address entry_point, Register arg_1, Register arg_2, Register arg_3); 112 113 // bytecodes 114 static void nop(); 115 116 static void aconst_null(); 117 static void iconst(int value); 118 static void lconst(int value); 119 static void fconst(int value); 120 static void dconst(int value); 121 122 static void bipush(); 123 static void sipush(); 124 static void ldc(bool wide); 125 static void ldc2_w(); 126 static void fast_aldc(bool wide); 127 128 static void locals_index(Register reg, int offset = 1); 129 static void iload(); 130 static void fast_iload(); 131 static void fast_iload2(); 132 static void fast_icaload(); 133 static void lload(); 134 static void fload(); 135 static void dload(); 136 static void aload(); 137 138 static void locals_index_wide(Register reg); 139 static void wide_iload(); 140 static void wide_lload(); 141 static void wide_fload(); 142 static void wide_dload(); 143 static void wide_aload(); 144 145 static void iaload(); 146 static void laload(); 147 static void faload(); 148 static void daload(); 149 static void aaload(); 150 static void baload(); 151 static void caload(); 152 static void saload(); 153 154 static void iload(int n); 155 static void lload(int n); 156 static void fload(int n); 157 static void dload(int n); 158 static void aload(int n); 159 static void aload_0(); 160 161 static void istore(); 162 static void lstore(); 163 static void fstore(); 164 static void dstore(); 165 static void astore(); 166 167 static void wide_istore(); 168 static void wide_lstore(); 169 static void wide_fstore(); 170 static void wide_dstore(); 171 static void wide_astore(); 172 173 static void iastore(); 174 static void lastore(); 175 static void fastore(); 176 static void dastore(); 177 static void aastore(); 178 static void bastore(); 179 static void castore(); 180 static void sastore(); 181 182 static void istore(int n); 183 static void lstore(int n); 184 static void fstore(int n); 185 static void dstore(int n); 186 static void astore(int n); 187 188 static void pop(); 189 static void pop2(); 190 static void dup(); 191 static void dup_x1(); 192 static void dup_x2(); 193 static void dup2(); 194 static void dup2_x1(); 195 static void dup2_x2(); 196 static void swap(); 197 198 static void iop2(Operation op); 199 static void lop2(Operation op); 200 static void fop2(Operation op); 201 static void dop2(Operation op); 202 203 static void idiv(); 204 static void irem(); 205 206 static void lmul(); 207 static void ldiv(); 208 static void lrem(); 209 static void lshl(); 210 static void lshr(); 211 static void lushr(); 212 213 static void ineg(); 214 static void lneg(); 215 static void fneg(); 216 static void dneg(); 217 218 static void iinc(); 219 static void wide_iinc(); 220 static void convert(); 221 static void lcmp(); 222 223 static void float_cmp (bool is_float, int unordered_result); 224 static void float_cmp (int unordered_result); 225 static void double_cmp(int unordered_result); 226 227 static void count_calls(Register method, Register temp); 228 static void branch(bool is_jsr, bool is_wide); 229 static void if_0cmp (Condition cc); 230 static void if_icmp (Condition cc); 231 static void if_nullcmp(Condition cc); 232 static void if_acmp (Condition cc); 233 234 static void _goto(); 235 static void jsr(); 236 static void ret(); 237 static void wide_ret(); 238 239 static void goto_w(); 240 static void jsr_w(); 241 242 static void tableswitch(); 243 static void lookupswitch(); 244 static void fast_linearswitch(); 245 static void fast_binaryswitch(); 246 247 static void _return(TosState state); 248 249 static void resolve_cache_and_index(int byte_no, // one of 1,2,11 250 Register result , // either noreg or output for f1/f2 251 Register cache, // output for CP cache 252 Register index, // output for CP index 253 size_t index_size); // one of 1,2,4 254 static void load_invoke_cp_cache_entry(int byte_no, 255 Register method, 256 Register itable_index, 257 Register flags, 258 bool is_invokevirtual, 259 bool is_virtual_final, 260 bool is_invokedynamic); 261 static void load_field_cp_cache_entry(Register obj, 262 Register cache, 263 Register index, 264 Register offset, 265 Register flags, 266 bool is_static); 267 static void invokevirtual(int byte_no); 268 static void invokespecial(int byte_no); 269 static void invokestatic(int byte_no); 270 static void invokeinterface(int byte_no); 271 static void invokedynamic(int byte_no); 272 static void fast_invokevfinal(int byte_no); 273 274 static void getfield_or_static(int byte_no, bool is_static); 275 static void putfield_or_static(int byte_no, bool is_static); 276 static void getfield(int byte_no); 277 static void putfield(int byte_no); 278 static void getstatic(int byte_no); 279 static void putstatic(int byte_no); 280 static void pop_and_check_object(Register obj); 281 282 static void _new(); 283 static void newarray(); 284 static void anewarray(); 285 static void arraylength(); 286 static void checkcast(); 287 static void instanceof(); 288 289 static void athrow(); 290 291 static void monitorenter(); 292 static void monitorexit(); 293 294 static void wide(); 295 static void multianewarray(); 296 297 static void fast_xaccess(TosState state); 298 static void fast_accessfield(TosState state); 299 static void fast_storefield(TosState state); 300 301 static void _breakpoint(); 302 303 static void shouldnotreachhere(); 304 305 // jvmti support 306 static void jvmti_post_field_access(Register cache, Register index, bool is_static, bool has_tos); 307 static void jvmti_post_field_mod(Register cache, Register index, bool is_static); 308 static void jvmti_post_fast_field_mod(); 309 310 // debugging of TemplateGenerator 311 static void transition(TosState tos_in, TosState tos_out);// checks if in/out states expected by template generator correspond to table entries 312 313 // initialization helpers 314 static void def(Bytecodes::Code code, int flags, TosState in, TosState out, void (*gen)( ), char filler ); 315 static void def(Bytecodes::Code code, int flags, TosState in, TosState out, void (*gen)(int arg ), int arg ); 316 static void def(Bytecodes::Code code, int flags, TosState in, TosState out, void (*gen)(bool arg ), bool arg ); 317 static void def(Bytecodes::Code code, int flags, TosState in, TosState out, void (*gen)(TosState tos), TosState tos); 318 static void def(Bytecodes::Code code, int flags, TosState in, TosState out, void (*gen)(Operation op), Operation op); 319 static void def(Bytecodes::Code code, int flags, TosState in, TosState out, void (*gen)(Condition cc), Condition cc); 320 321 friend class Template; 322 323 // InterpreterMacroAssembler::is_a(), etc., need TemplateTable::call_VM(). 324 friend class InterpreterMacroAssembler; 325 326 public: 327 // Initialization 328 static void initialize(); 329 static void pd_initialize(); 330 331 // Templates 332 static Template* template_for (Bytecodes::Code code) { Bytecodes::check (code); return &_template_table [code]; } 333 static Template* template_for_wide(Bytecodes::Code code) { Bytecodes::wide_check(code); return &_template_table_wide[code]; } 334 335 // Platform specifics 336 #include "incls/_templateTable_pd.hpp.incl" 337 }; 338 #endif /* !CC_INTERP */