src/share/vm/oops/constMethodOop.hpp

Mon, 09 Mar 2009 13:28:46 -0700

author
xdono
date
Mon, 09 Mar 2009 13:28:46 -0700
changeset 1014
0fbdb4381b99
parent 953
0af8b0718fc9
child 1573
dd57230ba8fe
permissions
-rw-r--r--

6814575: Update copyright year
Summary: Update copyright for files that have been modified in 2009, up to 03/09
Reviewed-by: katleman, tbell, ohair

duke@435 1 /*
xdono@1014 2 * Copyright 2003-2009 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 // An constMethodOop represents portions of a Java method which
duke@435 26 // do not vary.
duke@435 27 //
duke@435 28 // Memory layout (each line represents a word). Note that most
duke@435 29 // applications load thousands of methods, so keeping the size of this
duke@435 30 // structure small has a big impact on footprint.
duke@435 31 //
duke@435 32 // |------------------------------------------------------|
duke@435 33 // | header |
duke@435 34 // | klass |
duke@435 35 // |------------------------------------------------------|
duke@435 36 // | fingerprint 1 |
duke@435 37 // | fingerprint 2 |
duke@435 38 // | method (oop) |
duke@435 39 // | stackmap_data (oop) |
duke@435 40 // | exception_table (oop) |
duke@435 41 // | constMethod_size |
duke@435 42 // | interp_kind | flags | code_size |
duke@435 43 // | name index | signature index |
duke@435 44 // | method_idnum | generic_signature_index |
duke@435 45 // |------------------------------------------------------|
duke@435 46 // | |
duke@435 47 // | byte codes |
duke@435 48 // | |
duke@435 49 // |------------------------------------------------------|
duke@435 50 // | compressed linenumber table |
duke@435 51 // | (see class CompressedLineNumberReadStream) |
duke@435 52 // | (note that length is unknown until decompressed) |
duke@435 53 // | (access flags bit tells whether table is present) |
duke@435 54 // | (indexed from start of constMethodOop) |
duke@435 55 // | (elements not necessarily sorted!) |
duke@435 56 // |------------------------------------------------------|
duke@435 57 // | localvariable table elements + length (length last) |
duke@435 58 // | (length is u2, elements are 6-tuples of u2) |
duke@435 59 // | (see class LocalVariableTableElement) |
duke@435 60 // | (access flags bit tells whether table is present) |
duke@435 61 // | (indexed from end of contMethodOop) |
duke@435 62 // |------------------------------------------------------|
duke@435 63 // | checked exceptions elements + length (length last) |
duke@435 64 // | (length is u2, elements are u2) |
duke@435 65 // | (see class CheckedExceptionElement) |
duke@435 66 // | (access flags bit tells whether table is present) |
duke@435 67 // | (indexed from end of constMethodOop) |
duke@435 68 // |------------------------------------------------------|
duke@435 69
duke@435 70
duke@435 71 // Utitily class decribing elements in checked exceptions table inlined in methodOop.
duke@435 72 class CheckedExceptionElement VALUE_OBJ_CLASS_SPEC {
duke@435 73 public:
duke@435 74 u2 class_cp_index;
duke@435 75 };
duke@435 76
duke@435 77
duke@435 78 // Utitily class decribing elements in local variable table inlined in methodOop.
duke@435 79 class LocalVariableTableElement VALUE_OBJ_CLASS_SPEC {
duke@435 80 public:
duke@435 81 u2 start_bci;
duke@435 82 u2 length;
duke@435 83 u2 name_cp_index;
duke@435 84 u2 descriptor_cp_index;
duke@435 85 u2 signature_cp_index;
duke@435 86 u2 slot;
duke@435 87 };
duke@435 88
duke@435 89
duke@435 90 class constMethodOopDesc : public oopDesc {
duke@435 91 friend class constMethodKlass;
duke@435 92 friend class VMStructs;
duke@435 93 private:
duke@435 94 enum {
duke@435 95 _has_linenumber_table = 1,
duke@435 96 _has_checked_exceptions = 2,
duke@435 97 _has_localvariable_table = 4
duke@435 98 };
duke@435 99
duke@435 100 // Bit vector of signature
duke@435 101 // Callers interpret 0=not initialized yet and
duke@435 102 // -1=too many args to fix, must parse the slow way.
duke@435 103 // The real initial value is special to account for nonatomicity of 64 bit
duke@435 104 // loads and stores. This value may updated and read without a lock by
duke@435 105 // multiple threads, so is volatile.
duke@435 106 volatile uint64_t _fingerprint;
jmasa@953 107 volatile bool _is_conc_safe; // if true, safe for concurrent GC processing
duke@435 108
duke@435 109 public:
duke@435 110 oop* oop_block_beg() const { return adr_method(); }
duke@435 111 oop* oop_block_end() const { return adr_exception_table() + 1; }
duke@435 112
duke@435 113 private:
duke@435 114 //
duke@435 115 // The oop block. See comment in klass.hpp before making changes.
duke@435 116 //
duke@435 117
duke@435 118 // Backpointer to non-const methodOop (needed for some JVMTI operations)
duke@435 119 methodOop _method;
duke@435 120
duke@435 121 // Raw stackmap data for the method
duke@435 122 typeArrayOop _stackmap_data;
duke@435 123
duke@435 124 // The exception handler table. 4-tuples of ints [start_pc, end_pc,
duke@435 125 // handler_pc, catch_type index] For methods with no exceptions the
duke@435 126 // table is pointing to Universe::the_empty_int_array
duke@435 127 typeArrayOop _exception_table;
duke@435 128
duke@435 129 //
duke@435 130 // End of the oop block.
duke@435 131 //
duke@435 132
duke@435 133 int _constMethod_size;
duke@435 134 jbyte _interpreter_kind;
duke@435 135 jbyte _flags;
duke@435 136
duke@435 137 // Size of Java bytecodes allocated immediately after methodOop.
duke@435 138 u2 _code_size;
duke@435 139 u2 _name_index; // Method name (index in constant pool)
duke@435 140 u2 _signature_index; // Method signature (index in constant pool)
duke@435 141 u2 _method_idnum; // unique identification number for the method within the class
duke@435 142 // initially corresponds to the index into the methods array.
duke@435 143 // but this may change with redefinition
duke@435 144 u2 _generic_signature_index; // Generic signature (index in constant pool, 0 if absent)
duke@435 145
duke@435 146 public:
duke@435 147 // Inlined tables
duke@435 148 void set_inlined_tables_length(int checked_exceptions_len,
duke@435 149 int compressed_line_number_size,
duke@435 150 int localvariable_table_len);
duke@435 151
duke@435 152 bool has_linenumber_table() const
duke@435 153 { return (_flags & _has_linenumber_table) != 0; }
duke@435 154
duke@435 155 bool has_checked_exceptions() const
duke@435 156 { return (_flags & _has_checked_exceptions) != 0; }
duke@435 157
duke@435 158 bool has_localvariable_table() const
duke@435 159 { return (_flags & _has_localvariable_table) != 0; }
duke@435 160
duke@435 161 void set_interpreter_kind(int kind) { _interpreter_kind = kind; }
duke@435 162 int interpreter_kind(void) const { return _interpreter_kind; }
duke@435 163
duke@435 164 // backpointer to non-const methodOop
duke@435 165 methodOop method() const { return _method; }
duke@435 166 void set_method(methodOop m) { oop_store_without_check((oop*)&_method, (oop) m); }
duke@435 167
duke@435 168
duke@435 169 // stackmap table data
duke@435 170 typeArrayOop stackmap_data() const { return _stackmap_data; }
duke@435 171 void set_stackmap_data(typeArrayOop sd) {
duke@435 172 oop_store_without_check((oop*)&_stackmap_data, (oop)sd);
duke@435 173 }
duke@435 174 bool has_stackmap_table() const { return _stackmap_data != NULL; }
duke@435 175
duke@435 176 // exception handler table
duke@435 177 typeArrayOop exception_table() const { return _exception_table; }
duke@435 178 void set_exception_table(typeArrayOop e) { oop_store_without_check((oop*) &_exception_table, (oop) e); }
duke@435 179 bool has_exception_handler() const { return exception_table() != NULL && exception_table()->length() > 0; }
duke@435 180
duke@435 181 void init_fingerprint() {
duke@435 182 const uint64_t initval = CONST64(0x8000000000000000);
duke@435 183 _fingerprint = initval;
duke@435 184 }
duke@435 185
duke@435 186 uint64_t fingerprint() const {
duke@435 187 // Since reads aren't atomic for 64 bits, if any of the high or low order
duke@435 188 // word is the initial value, return 0. See init_fingerprint for initval.
duke@435 189 uint high_fp = (uint)(_fingerprint >> 32);
duke@435 190 if ((int) _fingerprint == 0 || high_fp == 0x80000000) {
duke@435 191 return 0L;
duke@435 192 } else {
duke@435 193 return _fingerprint;
duke@435 194 }
duke@435 195 }
duke@435 196
duke@435 197 uint64_t set_fingerprint(uint64_t new_fingerprint) {
duke@435 198 #ifdef ASSERT
duke@435 199 // Assert only valid if complete/valid 64 bit _fingerprint value is read.
duke@435 200 uint64_t oldfp = fingerprint();
duke@435 201 #endif // ASSERT
duke@435 202 _fingerprint = new_fingerprint;
duke@435 203 assert(oldfp == 0L || new_fingerprint == oldfp,
duke@435 204 "fingerprint cannot change");
duke@435 205 assert(((new_fingerprint >> 32) != 0x80000000) && (int)new_fingerprint !=0,
duke@435 206 "fingerprint should call init to set initial value");
duke@435 207 return new_fingerprint;
duke@435 208 }
duke@435 209
duke@435 210 // name
duke@435 211 int name_index() const { return _name_index; }
duke@435 212 void set_name_index(int index) { _name_index = index; }
duke@435 213
duke@435 214 // signature
duke@435 215 int signature_index() const { return _signature_index; }
duke@435 216 void set_signature_index(int index) { _signature_index = index; }
duke@435 217
duke@435 218 // generics support
duke@435 219 int generic_signature_index() const { return _generic_signature_index; }
duke@435 220 void set_generic_signature_index(int index) { _generic_signature_index = index; }
duke@435 221
duke@435 222 // Sizing
duke@435 223 static int header_size() {
duke@435 224 return sizeof(constMethodOopDesc)/HeapWordSize;
duke@435 225 }
duke@435 226
duke@435 227 // Object size needed
duke@435 228 static int object_size(int code_size, int compressed_line_number_size,
duke@435 229 int local_variable_table_length,
duke@435 230 int checked_exceptions_length);
duke@435 231
duke@435 232 int object_size() const { return _constMethod_size; }
duke@435 233 void set_constMethod_size(int size) { _constMethod_size = size; }
duke@435 234 // Is object parsable by gc
duke@435 235 bool object_is_parsable() { return object_size() > 0; }
duke@435 236
duke@435 237 // code size
duke@435 238 int code_size() const { return _code_size; }
duke@435 239 void set_code_size(int size) {
duke@435 240 assert(max_method_code_size < (1 << 16),
duke@435 241 "u2 is too small to hold method code size in general");
duke@435 242 assert(0 <= size && size <= max_method_code_size, "invalid code size");
duke@435 243 _code_size = size;
duke@435 244 }
duke@435 245
duke@435 246 // linenumber table - note that length is unknown until decompression,
duke@435 247 // see class CompressedLineNumberReadStream.
duke@435 248 u_char* compressed_linenumber_table() const; // not preserved by gc
duke@435 249 u2* checked_exceptions_length_addr() const;
duke@435 250 u2* localvariable_table_length_addr() const;
duke@435 251
duke@435 252 // checked exceptions
duke@435 253 int checked_exceptions_length() const;
duke@435 254 CheckedExceptionElement* checked_exceptions_start() const;
duke@435 255
duke@435 256 // localvariable table
duke@435 257 int localvariable_table_length() const;
duke@435 258 LocalVariableTableElement* localvariable_table_start() const;
duke@435 259
duke@435 260 // byte codes
duke@435 261 address code_base() const { return (address) (this+1); }
duke@435 262 address code_end() const { return code_base() + code_size(); }
duke@435 263 bool contains(address bcp) const { return code_base() <= bcp
duke@435 264 && bcp < code_end(); }
duke@435 265 // Offset to bytecodes
duke@435 266 static ByteSize codes_offset()
duke@435 267 { return in_ByteSize(sizeof(constMethodOopDesc)); }
duke@435 268
duke@435 269 // interpreter support
duke@435 270 static ByteSize exception_table_offset()
duke@435 271 { return byte_offset_of(constMethodOopDesc, _exception_table); }
duke@435 272
duke@435 273 // Garbage collection support
duke@435 274 oop* adr_method() const { return (oop*)&_method; }
duke@435 275 oop* adr_stackmap_data() const { return (oop*)&_stackmap_data; }
duke@435 276 oop* adr_exception_table() const { return (oop*)&_exception_table; }
jmasa@953 277 bool is_conc_safe() { return _is_conc_safe; }
jmasa@953 278 void set_is_conc_safe(bool v) { _is_conc_safe = v; }
duke@435 279
duke@435 280 // Unique id for the method
duke@435 281 static const u2 MAX_IDNUM;
duke@435 282 static const u2 UNSET_IDNUM;
duke@435 283 u2 method_idnum() const { return _method_idnum; }
duke@435 284 void set_method_idnum(u2 idnum) { _method_idnum = idnum; }
duke@435 285
duke@435 286 private:
duke@435 287 // Since the size of the compressed line number table is unknown, the
duke@435 288 // offsets of the other variable sized sections are computed backwards
duke@435 289 // from the end of the constMethodOop.
duke@435 290
duke@435 291 // First byte after constMethodOop
duke@435 292 address constMethod_end() const
duke@435 293 { return (address)((oop*)this + _constMethod_size); }
duke@435 294
duke@435 295 // Last short in constMethodOop
duke@435 296 u2* last_u2_element() const
duke@435 297 { return (u2*)constMethod_end() - 1; }
duke@435 298 };

mercurial