src/share/vm/interpreter/templateTable.hpp

Thu, 30 Oct 2008 15:48:59 -0400

author
kamg
date
Thu, 30 Oct 2008 15:48:59 -0400
changeset 848
c7ec737733a6
parent 777
37f87013dfd8
child 1161
be93aad57795
permissions
-rw-r--r--

6756528: Bytecodes::special_length_at reads past end of code buffer
Summary: Add end-of-buffer indicator for paths used by the verifier
Reviewed-by: acorn, coleenp

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

mercurial