annotate src/share/vm/oops/constMethodOop.hpp @ 45:48a3fa21394b

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