0N/A/*
3790N/A * Copyright (c) 2003, 2012, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
0N/A * published by the Free Software Foundation.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
1472N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
1472N/A * or visit www.oracle.com if you need additional information or have any
1472N/A * questions.
0N/A *
0N/A */
0N/A
1879N/A#ifndef SHARE_VM_OOPS_CONSTMETHODOOP_HPP
1879N/A#define SHARE_VM_OOPS_CONSTMETHODOOP_HPP
1879N/A
1879N/A#include "oops/oop.hpp"
1879N/A#include "oops/typeArrayOop.hpp"
1879N/A
0N/A// An constMethodOop represents portions of a Java method which
0N/A// do not vary.
0N/A//
0N/A// Memory layout (each line represents a word). Note that most
0N/A// applications load thousands of methods, so keeping the size of this
0N/A// structure small has a big impact on footprint.
0N/A//
0N/A// |------------------------------------------------------|
0N/A// | header |
0N/A// | klass |
0N/A// |------------------------------------------------------|
0N/A// | fingerprint 1 |
0N/A// | fingerprint 2 |
3790N/A// | constants (oop) |
0N/A// | stackmap_data (oop) |
0N/A// | constMethod_size |
0N/A// | interp_kind | flags | code_size |
0N/A// | name index | signature index |
0N/A// | method_idnum | generic_signature_index |
0N/A// |------------------------------------------------------|
0N/A// | |
0N/A// | byte codes |
0N/A// | |
0N/A// |------------------------------------------------------|
0N/A// | compressed linenumber table |
0N/A// | (see class CompressedLineNumberReadStream) |
0N/A// | (note that length is unknown until decompressed) |
0N/A// | (access flags bit tells whether table is present) |
0N/A// | (indexed from start of constMethodOop) |
0N/A// | (elements not necessarily sorted!) |
0N/A// |------------------------------------------------------|
0N/A// | localvariable table elements + length (length last) |
0N/A// | (length is u2, elements are 6-tuples of u2) |
0N/A// | (see class LocalVariableTableElement) |
0N/A// | (access flags bit tells whether table is present) |
3879N/A// | (indexed from end of constMethodOop) |
3879N/A// |------------------------------------------------------|
3879N/A// | exception table + length (length last) |
3879N/A// | (length is u2, elements are 4-tuples of u2) |
3879N/A// | (see class ExceptionTableElement) |
3879N/A// | (access flags bit tells whether table is present) |
3879N/A// | (indexed from end of constMethodOop) |
0N/A// |------------------------------------------------------|
0N/A// | checked exceptions elements + length (length last) |
0N/A// | (length is u2, elements are u2) |
0N/A// | (see class CheckedExceptionElement) |
0N/A// | (access flags bit tells whether table is present) |
0N/A// | (indexed from end of constMethodOop) |
0N/A// |------------------------------------------------------|
0N/A
0N/A
0N/A// Utitily class decribing elements in checked exceptions table inlined in methodOop.
0N/Aclass CheckedExceptionElement VALUE_OBJ_CLASS_SPEC {
0N/A public:
0N/A u2 class_cp_index;
0N/A};
0N/A
0N/A
0N/A// Utitily class decribing elements in local variable table inlined in methodOop.
0N/Aclass LocalVariableTableElement VALUE_OBJ_CLASS_SPEC {
0N/A public:
0N/A u2 start_bci;
0N/A u2 length;
0N/A u2 name_cp_index;
0N/A u2 descriptor_cp_index;
0N/A u2 signature_cp_index;
0N/A u2 slot;
0N/A};
0N/A
0N/A
3879N/A// Utitily class describing elements in exception table
3879N/Aclass ExceptionTableElement VALUE_OBJ_CLASS_SPEC {
3879N/A public:
3879N/A u2 start_pc;
3879N/A u2 end_pc;
3879N/A u2 handler_pc;
3879N/A u2 catch_type_index;
3879N/A};
3879N/A
0N/Aclass constMethodOopDesc : public oopDesc {
0N/A friend class constMethodKlass;
0N/A friend class VMStructs;
0N/Aprivate:
0N/A enum {
0N/A _has_linenumber_table = 1,
0N/A _has_checked_exceptions = 2,
3879N/A _has_localvariable_table = 4,
3879N/A _has_exception_table = 8
0N/A };
0N/A
0N/A // Bit vector of signature
0N/A // Callers interpret 0=not initialized yet and
0N/A // -1=too many args to fix, must parse the slow way.
0N/A // The real initial value is special to account for nonatomicity of 64 bit
0N/A // loads and stores. This value may updated and read without a lock by
0N/A // multiple threads, so is volatile.
0N/A volatile uint64_t _fingerprint;
518N/A volatile bool _is_conc_safe; // if true, safe for concurrent GC processing
0N/A
0N/Apublic:
3790N/A oop* oop_block_beg() const { return adr_constants(); }
3879N/A oop* oop_block_end() const { return adr_stackmap_data() + 1; }
0N/A
0N/Aprivate:
0N/A //
0N/A // The oop block. See comment in klass.hpp before making changes.
0N/A //
0N/A
3790N/A constantPoolOop _constants; // Constant pool
0N/A
0N/A // Raw stackmap data for the method
0N/A typeArrayOop _stackmap_data;
0N/A
0N/A //
0N/A // End of the oop block.
0N/A //
0N/A
0N/A int _constMethod_size;
0N/A jbyte _interpreter_kind;
0N/A jbyte _flags;
0N/A
0N/A // Size of Java bytecodes allocated immediately after methodOop.
0N/A u2 _code_size;
0N/A u2 _name_index; // Method name (index in constant pool)
0N/A u2 _signature_index; // Method signature (index in constant pool)
0N/A u2 _method_idnum; // unique identification number for the method within the class
0N/A // initially corresponds to the index into the methods array.
0N/A // but this may change with redefinition
0N/A u2 _generic_signature_index; // Generic signature (index in constant pool, 0 if absent)
0N/A
0N/Apublic:
0N/A // Inlined tables
0N/A void set_inlined_tables_length(int checked_exceptions_len,
0N/A int compressed_line_number_size,
3879N/A int localvariable_table_len,
3879N/A int exception_table_len);
0N/A
0N/A bool has_linenumber_table() const
0N/A { return (_flags & _has_linenumber_table) != 0; }
0N/A
0N/A bool has_checked_exceptions() const
0N/A { return (_flags & _has_checked_exceptions) != 0; }
0N/A
0N/A bool has_localvariable_table() const
0N/A { return (_flags & _has_localvariable_table) != 0; }
0N/A
3879N/A bool has_exception_handler() const
3879N/A { return (_flags & _has_exception_table) != 0; }
3879N/A
0N/A void set_interpreter_kind(int kind) { _interpreter_kind = kind; }
0N/A int interpreter_kind(void) const { return _interpreter_kind; }
0N/A
3790N/A // constant pool
3790N/A constantPoolOop constants() const { return _constants; }
3790N/A void set_constants(constantPoolOop c) {
3790N/A oop_store_without_check((oop*)&_constants, (oop)c);
3790N/A }
0N/A
3790N/A methodOop method() const;
0N/A
0N/A // stackmap table data
0N/A typeArrayOop stackmap_data() const { return _stackmap_data; }
0N/A void set_stackmap_data(typeArrayOop sd) {
0N/A oop_store_without_check((oop*)&_stackmap_data, (oop)sd);
0N/A }
0N/A bool has_stackmap_table() const { return _stackmap_data != NULL; }
0N/A
0N/A void init_fingerprint() {
0N/A const uint64_t initval = CONST64(0x8000000000000000);
0N/A _fingerprint = initval;
0N/A }
0N/A
0N/A uint64_t fingerprint() const {
0N/A // Since reads aren't atomic for 64 bits, if any of the high or low order
0N/A // word is the initial value, return 0. See init_fingerprint for initval.
0N/A uint high_fp = (uint)(_fingerprint >> 32);
0N/A if ((int) _fingerprint == 0 || high_fp == 0x80000000) {
0N/A return 0L;
0N/A } else {
0N/A return _fingerprint;
0N/A }
0N/A }
0N/A
0N/A uint64_t set_fingerprint(uint64_t new_fingerprint) {
0N/A#ifdef ASSERT
0N/A // Assert only valid if complete/valid 64 bit _fingerprint value is read.
0N/A uint64_t oldfp = fingerprint();
0N/A#endif // ASSERT
0N/A _fingerprint = new_fingerprint;
0N/A assert(oldfp == 0L || new_fingerprint == oldfp,
0N/A "fingerprint cannot change");
0N/A assert(((new_fingerprint >> 32) != 0x80000000) && (int)new_fingerprint !=0,
0N/A "fingerprint should call init to set initial value");
0N/A return new_fingerprint;
0N/A }
0N/A
0N/A // name
0N/A int name_index() const { return _name_index; }
0N/A void set_name_index(int index) { _name_index = index; }
0N/A
0N/A // signature
0N/A int signature_index() const { return _signature_index; }
0N/A void set_signature_index(int index) { _signature_index = index; }
0N/A
0N/A // generics support
0N/A int generic_signature_index() const { return _generic_signature_index; }
0N/A void set_generic_signature_index(int index) { _generic_signature_index = index; }
0N/A
0N/A // Sizing
0N/A static int header_size() {
0N/A return sizeof(constMethodOopDesc)/HeapWordSize;
0N/A }
0N/A
0N/A // Object size needed
0N/A static int object_size(int code_size, int compressed_line_number_size,
0N/A int local_variable_table_length,
3879N/A int exception_table_length,
0N/A int checked_exceptions_length);
0N/A
0N/A int object_size() const { return _constMethod_size; }
0N/A void set_constMethod_size(int size) { _constMethod_size = size; }
0N/A // Is object parsable by gc
0N/A bool object_is_parsable() { return object_size() > 0; }
0N/A
0N/A // code size
0N/A int code_size() const { return _code_size; }
0N/A void set_code_size(int size) {
0N/A assert(max_method_code_size < (1 << 16),
0N/A "u2 is too small to hold method code size in general");
0N/A assert(0 <= size && size <= max_method_code_size, "invalid code size");
0N/A _code_size = size;
0N/A }
0N/A
0N/A // linenumber table - note that length is unknown until decompression,
0N/A // see class CompressedLineNumberReadStream.
0N/A u_char* compressed_linenumber_table() const; // not preserved by gc
0N/A u2* checked_exceptions_length_addr() const;
0N/A u2* localvariable_table_length_addr() const;
3879N/A u2* exception_table_length_addr() const;
0N/A
0N/A // checked exceptions
0N/A int checked_exceptions_length() const;
0N/A CheckedExceptionElement* checked_exceptions_start() const;
0N/A
0N/A // localvariable table
0N/A int localvariable_table_length() const;
0N/A LocalVariableTableElement* localvariable_table_start() const;
0N/A
3879N/A // exception table
3879N/A int exception_table_length() const;
3879N/A ExceptionTableElement* exception_table_start() const;
3879N/A
0N/A // byte codes
1138N/A void set_code(address code) {
1138N/A if (code_size() > 0) {
1138N/A memcpy(code_base(), code, code_size());
1138N/A }
1138N/A }
0N/A address code_base() const { return (address) (this+1); }
0N/A address code_end() const { return code_base() + code_size(); }
0N/A bool contains(address bcp) const { return code_base() <= bcp
0N/A && bcp < code_end(); }
0N/A // Offset to bytecodes
0N/A static ByteSize codes_offset()
0N/A { return in_ByteSize(sizeof(constMethodOopDesc)); }
0N/A
0N/A // interpreter support
3790N/A static ByteSize constants_offset()
3790N/A { return byte_offset_of(constMethodOopDesc, _constants); }
0N/A
0N/A // Garbage collection support
3790N/A oop* adr_constants() const { return (oop*)&_constants; }
0N/A oop* adr_stackmap_data() const { return (oop*)&_stackmap_data; }
518N/A bool is_conc_safe() { return _is_conc_safe; }
518N/A void set_is_conc_safe(bool v) { _is_conc_safe = v; }
0N/A
0N/A // Unique id for the method
0N/A static const u2 MAX_IDNUM;
0N/A static const u2 UNSET_IDNUM;
0N/A u2 method_idnum() const { return _method_idnum; }
0N/A void set_method_idnum(u2 idnum) { _method_idnum = idnum; }
0N/A
0N/Aprivate:
0N/A // Since the size of the compressed line number table is unknown, the
0N/A // offsets of the other variable sized sections are computed backwards
0N/A // from the end of the constMethodOop.
0N/A
0N/A // First byte after constMethodOop
0N/A address constMethod_end() const
0N/A { return (address)((oop*)this + _constMethod_size); }
0N/A
0N/A // Last short in constMethodOop
0N/A u2* last_u2_element() const
0N/A { return (u2*)constMethod_end() - 1; }
0N/A};
1879N/A
1879N/A#endif // SHARE_VM_OOPS_CONSTMETHODOOP_HPP