src/share/vm/oops/constMethodOop.hpp

Wed, 05 Dec 2007 09:00:00 -0800

author
dcubed
date
Wed, 05 Dec 2007 09:00:00 -0800
changeset 451
f8236e79048a
parent 435
a61af66fc99e
child 953
0af8b0718fc9
permissions
-rw-r--r--

6664627: Merge changes made only in hotspot 11 forward to jdk 7
Reviewed-by: jcoomes

duke@435 1 /*
duke@435 2 * Copyright 2003-2006 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;
duke@435 107
duke@435 108 public:
duke@435 109 oop* oop_block_beg() const { return adr_method(); }
duke@435 110 oop* oop_block_end() const { return adr_exception_table() + 1; }
duke@435 111
duke@435 112 private:
duke@435 113 //
duke@435 114 // The oop block. See comment in klass.hpp before making changes.
duke@435 115 //
duke@435 116
duke@435 117 // Backpointer to non-const methodOop (needed for some JVMTI operations)
duke@435 118 methodOop _method;
duke@435 119
duke@435 120 // Raw stackmap data for the method
duke@435 121 typeArrayOop _stackmap_data;
duke@435 122
duke@435 123 // The exception handler table. 4-tuples of ints [start_pc, end_pc,
duke@435 124 // handler_pc, catch_type index] For methods with no exceptions the
duke@435 125 // table is pointing to Universe::the_empty_int_array
duke@435 126 typeArrayOop _exception_table;
duke@435 127
duke@435 128 //
duke@435 129 // End of the oop block.
duke@435 130 //
duke@435 131
duke@435 132 int _constMethod_size;
duke@435 133 jbyte _interpreter_kind;
duke@435 134 jbyte _flags;
duke@435 135
duke@435 136 // Size of Java bytecodes allocated immediately after methodOop.
duke@435 137 u2 _code_size;
duke@435 138 u2 _name_index; // Method name (index in constant pool)
duke@435 139 u2 _signature_index; // Method signature (index in constant pool)
duke@435 140 u2 _method_idnum; // unique identification number for the method within the class
duke@435 141 // initially corresponds to the index into the methods array.
duke@435 142 // but this may change with redefinition
duke@435 143 u2 _generic_signature_index; // Generic signature (index in constant pool, 0 if absent)
duke@435 144
duke@435 145 public:
duke@435 146 // Inlined tables
duke@435 147 void set_inlined_tables_length(int checked_exceptions_len,
duke@435 148 int compressed_line_number_size,
duke@435 149 int localvariable_table_len);
duke@435 150
duke@435 151 bool has_linenumber_table() const
duke@435 152 { return (_flags & _has_linenumber_table) != 0; }
duke@435 153
duke@435 154 bool has_checked_exceptions() const
duke@435 155 { return (_flags & _has_checked_exceptions) != 0; }
duke@435 156
duke@435 157 bool has_localvariable_table() const
duke@435 158 { return (_flags & _has_localvariable_table) != 0; }
duke@435 159
duke@435 160 void set_interpreter_kind(int kind) { _interpreter_kind = kind; }
duke@435 161 int interpreter_kind(void) const { return _interpreter_kind; }
duke@435 162
duke@435 163 // backpointer to non-const methodOop
duke@435 164 methodOop method() const { return _method; }
duke@435 165 void set_method(methodOop m) { oop_store_without_check((oop*)&_method, (oop) m); }
duke@435 166
duke@435 167
duke@435 168 // stackmap table data
duke@435 169 typeArrayOop stackmap_data() const { return _stackmap_data; }
duke@435 170 void set_stackmap_data(typeArrayOop sd) {
duke@435 171 oop_store_without_check((oop*)&_stackmap_data, (oop)sd);
duke@435 172 }
duke@435 173 bool has_stackmap_table() const { return _stackmap_data != NULL; }
duke@435 174
duke@435 175 // exception handler table
duke@435 176 typeArrayOop exception_table() const { return _exception_table; }
duke@435 177 void set_exception_table(typeArrayOop e) { oop_store_without_check((oop*) &_exception_table, (oop) e); }
duke@435 178 bool has_exception_handler() const { return exception_table() != NULL && exception_table()->length() > 0; }
duke@435 179
duke@435 180 void init_fingerprint() {
duke@435 181 const uint64_t initval = CONST64(0x8000000000000000);
duke@435 182 _fingerprint = initval;
duke@435 183 }
duke@435 184
duke@435 185 uint64_t fingerprint() const {
duke@435 186 // Since reads aren't atomic for 64 bits, if any of the high or low order
duke@435 187 // word is the initial value, return 0. See init_fingerprint for initval.
duke@435 188 uint high_fp = (uint)(_fingerprint >> 32);
duke@435 189 if ((int) _fingerprint == 0 || high_fp == 0x80000000) {
duke@435 190 return 0L;
duke@435 191 } else {
duke@435 192 return _fingerprint;
duke@435 193 }
duke@435 194 }
duke@435 195
duke@435 196 uint64_t set_fingerprint(uint64_t new_fingerprint) {
duke@435 197 #ifdef ASSERT
duke@435 198 // Assert only valid if complete/valid 64 bit _fingerprint value is read.
duke@435 199 uint64_t oldfp = fingerprint();
duke@435 200 #endif // ASSERT
duke@435 201 _fingerprint = new_fingerprint;
duke@435 202 assert(oldfp == 0L || new_fingerprint == oldfp,
duke@435 203 "fingerprint cannot change");
duke@435 204 assert(((new_fingerprint >> 32) != 0x80000000) && (int)new_fingerprint !=0,
duke@435 205 "fingerprint should call init to set initial value");
duke@435 206 return new_fingerprint;
duke@435 207 }
duke@435 208
duke@435 209 // name
duke@435 210 int name_index() const { return _name_index; }
duke@435 211 void set_name_index(int index) { _name_index = index; }
duke@435 212
duke@435 213 // signature
duke@435 214 int signature_index() const { return _signature_index; }
duke@435 215 void set_signature_index(int index) { _signature_index = index; }
duke@435 216
duke@435 217 // generics support
duke@435 218 int generic_signature_index() const { return _generic_signature_index; }
duke@435 219 void set_generic_signature_index(int index) { _generic_signature_index = index; }
duke@435 220
duke@435 221 // Sizing
duke@435 222 static int header_size() {
duke@435 223 return sizeof(constMethodOopDesc)/HeapWordSize;
duke@435 224 }
duke@435 225
duke@435 226 // Object size needed
duke@435 227 static int object_size(int code_size, int compressed_line_number_size,
duke@435 228 int local_variable_table_length,
duke@435 229 int checked_exceptions_length);
duke@435 230
duke@435 231 int object_size() const { return _constMethod_size; }
duke@435 232 void set_constMethod_size(int size) { _constMethod_size = size; }
duke@435 233 // Is object parsable by gc
duke@435 234 bool object_is_parsable() { return object_size() > 0; }
duke@435 235
duke@435 236 // code size
duke@435 237 int code_size() const { return _code_size; }
duke@435 238 void set_code_size(int size) {
duke@435 239 assert(max_method_code_size < (1 << 16),
duke@435 240 "u2 is too small to hold method code size in general");
duke@435 241 assert(0 <= size && size <= max_method_code_size, "invalid code size");
duke@435 242 _code_size = size;
duke@435 243 }
duke@435 244
duke@435 245 // linenumber table - note that length is unknown until decompression,
duke@435 246 // see class CompressedLineNumberReadStream.
duke@435 247 u_char* compressed_linenumber_table() const; // not preserved by gc
duke@435 248 u2* checked_exceptions_length_addr() const;
duke@435 249 u2* localvariable_table_length_addr() const;
duke@435 250
duke@435 251 // checked exceptions
duke@435 252 int checked_exceptions_length() const;
duke@435 253 CheckedExceptionElement* checked_exceptions_start() const;
duke@435 254
duke@435 255 // localvariable table
duke@435 256 int localvariable_table_length() const;
duke@435 257 LocalVariableTableElement* localvariable_table_start() const;
duke@435 258
duke@435 259 // byte codes
duke@435 260 address code_base() const { return (address) (this+1); }
duke@435 261 address code_end() const { return code_base() + code_size(); }
duke@435 262 bool contains(address bcp) const { return code_base() <= bcp
duke@435 263 && bcp < code_end(); }
duke@435 264 // Offset to bytecodes
duke@435 265 static ByteSize codes_offset()
duke@435 266 { return in_ByteSize(sizeof(constMethodOopDesc)); }
duke@435 267
duke@435 268 // interpreter support
duke@435 269 static ByteSize exception_table_offset()
duke@435 270 { return byte_offset_of(constMethodOopDesc, _exception_table); }
duke@435 271
duke@435 272 // Garbage collection support
duke@435 273 oop* adr_method() const { return (oop*)&_method; }
duke@435 274 oop* adr_stackmap_data() const { return (oop*)&_stackmap_data; }
duke@435 275 oop* adr_exception_table() const { return (oop*)&_exception_table; }
duke@435 276
duke@435 277 // Unique id for the method
duke@435 278 static const u2 MAX_IDNUM;
duke@435 279 static const u2 UNSET_IDNUM;
duke@435 280 u2 method_idnum() const { return _method_idnum; }
duke@435 281 void set_method_idnum(u2 idnum) { _method_idnum = idnum; }
duke@435 282
duke@435 283 private:
duke@435 284 // Since the size of the compressed line number table is unknown, the
duke@435 285 // offsets of the other variable sized sections are computed backwards
duke@435 286 // from the end of the constMethodOop.
duke@435 287
duke@435 288 // First byte after constMethodOop
duke@435 289 address constMethod_end() const
duke@435 290 { return (address)((oop*)this + _constMethod_size); }
duke@435 291
duke@435 292 // Last short in constMethodOop
duke@435 293 u2* last_u2_element() const
duke@435 294 { return (u2*)constMethod_end() - 1; }
duke@435 295 };

mercurial