src/share/vm/oops/constMethodOop.hpp

Tue, 26 Jun 2012 19:08:44 -0400

author
jiangli
date
Tue, 26 Jun 2012 19:08:44 -0400
changeset 3917
8150fa46d2ed
parent 3826
2fe087c3e814
permissions
-rw-r--r--

7178145: Change constMethodOop::_exception_table to optionally inlined u2 table.
Summary: Change constMethodOop::_exception_table to optionally inlined u2 table.
Reviewed-by: bdelsart, coleenp, kamg

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

mercurial