constMethodOop.cpp revision 1879
3853N/A/*
3853N/A * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
3853N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
3853N/A *
3853N/A * This code is free software; you can redistribute it and/or modify it
3853N/A * under the terms of the GNU General Public License version 2 only, as
3853N/A * published by the Free Software Foundation.
3853N/A *
3853N/A * This code is distributed in the hope that it will be useful, but WITHOUT
3853N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
3853N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
3853N/A * version 2 for more details (a copy is included in the LICENSE file that
3853N/A * accompanied this code).
3853N/A *
3853N/A * You should have received a copy of the GNU General Public License version
3853N/A * 2 along with this work; if not, write to the Free Software Foundation,
3853N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
3853N/A *
3853N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
3853N/A * or visit www.oracle.com if you need additional information or have any
3853N/A * questions.
3853N/A *
3853N/A */
3853N/A
4136N/A#include "precompiled.hpp"
3853N/A#include "oops/constMethodOop.hpp"
3853N/A#include "oops/methodOop.hpp"
3853N/A
3853N/A// Static initialization
3853N/Aconst u2 constMethodOopDesc::MAX_IDNUM = 0xFFFE;
3853N/Aconst u2 constMethodOopDesc::UNSET_IDNUM = 0xFFFF;
3853N/A
3853N/A// How big must this constMethodObject be?
3853N/A
3853N/Aint constMethodOopDesc::object_size(int code_size,
3853N/A int compressed_line_number_size,
3853N/A int local_variable_table_length,
3853N/A int checked_exceptions_length) {
3853N/A int extra_bytes = code_size;
3853N/A if (compressed_line_number_size > 0) {
3853N/A extra_bytes += compressed_line_number_size;
3853N/A }
3853N/A if (checked_exceptions_length > 0) {
3853N/A extra_bytes += sizeof(u2);
3853N/A extra_bytes += checked_exceptions_length * sizeof(CheckedExceptionElement);
3853N/A }
3853N/A if (local_variable_table_length > 0) {
3853N/A extra_bytes += sizeof(u2);
3853N/A extra_bytes +=
3853N/A local_variable_table_length * sizeof(LocalVariableTableElement);
3853N/A }
3853N/A int extra_words = align_size_up(extra_bytes, BytesPerWord) / BytesPerWord;
3853N/A return align_object_size(header_size() + extra_words);
3853N/A}
3853N/A
3853N/A
3853N/A// linenumber table - note that length is unknown until decompression,
3853N/A// see class CompressedLineNumberReadStream.
3853N/A
3853N/Au_char* constMethodOopDesc::compressed_linenumber_table() const {
3853N/A // Located immediately following the bytecodes.
3853N/A assert(has_linenumber_table(), "called only if table is present");
3853N/A return code_end();
3853N/A}
3853N/A
3853N/Au2* constMethodOopDesc::checked_exceptions_length_addr() const {
3853N/A // Located at the end of the constMethod.
3853N/A assert(has_checked_exceptions(), "called only if table is present");
3853N/A return last_u2_element();
3853N/A}
3853N/A
3853N/Au2* constMethodOopDesc::localvariable_table_length_addr() const {
3853N/A assert(has_localvariable_table(), "called only if table is present");
3853N/A if (has_checked_exceptions()) {
3853N/A // If checked_exception present, locate immediately before them.
3853N/A return (u2*) checked_exceptions_start() - 1;
3853N/A } else {
3853N/A // Else, the linenumber table is at the end of the constMethod.
3853N/A return last_u2_element();
3853N/A }
3853N/A}
3853N/A
3853N/A
3853N/A// Update the flags to indicate the presence of these optional fields.
3853N/Avoid constMethodOopDesc::set_inlined_tables_length(
3853N/A int checked_exceptions_len,
3853N/A int compressed_line_number_size,
3853N/A int localvariable_table_len) {
3853N/A // Must be done in the order below, otherwise length_addr accessors
3853N/A // will not work. Only set bit in header if length is positive.
3853N/A assert(_flags == 0, "Error");
3853N/A if (compressed_line_number_size > 0) {
3853N/A _flags |= _has_linenumber_table;
3853N/A }
3853N/A if (checked_exceptions_len > 0) {
3853N/A _flags |= _has_checked_exceptions;
3853N/A *(checked_exceptions_length_addr()) = checked_exceptions_len;
3853N/A }
3853N/A if (localvariable_table_len > 0) {
3853N/A _flags |= _has_localvariable_table;
3853N/A *(localvariable_table_length_addr()) = localvariable_table_len;
3853N/A }
3853N/A}
3853N/A
3919N/A
3853N/Aint constMethodOopDesc::checked_exceptions_length() const {
3853N/A return has_checked_exceptions() ? *(checked_exceptions_length_addr()) : 0;
3853N/A}
3853N/A
3853N/A
3853N/ACheckedExceptionElement* constMethodOopDesc::checked_exceptions_start() const {
3853N/A u2* addr = checked_exceptions_length_addr();
3853N/A u2 length = *addr;
3853N/A assert(length > 0, "should only be called if table is present");
3853N/A addr -= length * sizeof(CheckedExceptionElement) / sizeof(u2);
3853N/A return (CheckedExceptionElement*) addr;
3853N/A}
3853N/A
3853N/A
3853N/Aint constMethodOopDesc::localvariable_table_length() const {
3853N/A return has_localvariable_table() ? *(localvariable_table_length_addr()) : 0;
3853N/A}
3853N/A
3853N/A
3853N/ALocalVariableTableElement* constMethodOopDesc::localvariable_table_start() const {
3853N/A u2* addr = localvariable_table_length_addr();
3919N/A u2 length = *addr;
3919N/A assert(length > 0, "should only be called if table is present");
3919N/A addr -= length * sizeof(LocalVariableTableElement) / sizeof(u2);
3919N/A return (LocalVariableTableElement*) addr;
3919N/A}
3919N/A