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#include "precompiled.hpp"
1879N/A#include "oops/constMethodOop.hpp"
1879N/A#include "oops/methodOop.hpp"
0N/A
0N/A// Static initialization
0N/Aconst u2 constMethodOopDesc::MAX_IDNUM = 0xFFFE;
0N/Aconst u2 constMethodOopDesc::UNSET_IDNUM = 0xFFFF;
0N/A
0N/A// How big must this constMethodObject be?
0N/A
0N/Aint constMethodOopDesc::object_size(int code_size,
0N/A 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 int extra_bytes = code_size;
0N/A if (compressed_line_number_size > 0) {
0N/A extra_bytes += compressed_line_number_size;
0N/A }
0N/A if (checked_exceptions_length > 0) {
0N/A extra_bytes += sizeof(u2);
0N/A extra_bytes += checked_exceptions_length * sizeof(CheckedExceptionElement);
0N/A }
0N/A if (local_variable_table_length > 0) {
0N/A extra_bytes += sizeof(u2);
0N/A extra_bytes +=
0N/A local_variable_table_length * sizeof(LocalVariableTableElement);
0N/A }
3879N/A if (exception_table_length > 0) {
3879N/A extra_bytes += sizeof(u2);
3879N/A extra_bytes += exception_table_length * sizeof(ExceptionTableElement);
3879N/A }
0N/A int extra_words = align_size_up(extra_bytes, BytesPerWord) / BytesPerWord;
0N/A return align_object_size(header_size() + extra_words);
0N/A}
0N/A
3790N/AmethodOop constMethodOopDesc::method() const {
3790N/A return instanceKlass::cast(_constants->pool_holder())->method_with_idnum(
3790N/A _method_idnum);
3790N/A }
0N/A
0N/A// linenumber table - note that length is unknown until decompression,
0N/A// see class CompressedLineNumberReadStream.
0N/A
0N/Au_char* constMethodOopDesc::compressed_linenumber_table() const {
0N/A // Located immediately following the bytecodes.
0N/A assert(has_linenumber_table(), "called only if table is present");
0N/A return code_end();
0N/A}
0N/A
0N/Au2* constMethodOopDesc::checked_exceptions_length_addr() const {
0N/A // Located at the end of the constMethod.
0N/A assert(has_checked_exceptions(), "called only if table is present");
0N/A return last_u2_element();
0N/A}
0N/A
3879N/Au2* constMethodOopDesc::exception_table_length_addr() const {
3879N/A assert(has_exception_handler(), "called only if table is present");
0N/A if (has_checked_exceptions()) {
0N/A // If checked_exception present, locate immediately before them.
0N/A return (u2*) checked_exceptions_start() - 1;
0N/A } else {
3879N/A // Else, the exception table is at the end of the constMethod.
0N/A return last_u2_element();
0N/A }
0N/A}
0N/A
3879N/Au2* constMethodOopDesc::localvariable_table_length_addr() const {
3879N/A assert(has_localvariable_table(), "called only if table is present");
3879N/A if (has_exception_handler()) {
3879N/A // If exception_table present, locate immediately before them.
3879N/A return (u2*) exception_table_start() - 1;
3879N/A } else {
3879N/A if (has_checked_exceptions()) {
3879N/A // If checked_exception present, locate immediately before them.
3879N/A return (u2*) checked_exceptions_start() - 1;
3879N/A } else {
3879N/A // Else, the linenumber table is at the end of the constMethod.
3879N/A return last_u2_element();
3879N/A }
3879N/A }
3879N/A}
3879N/A
0N/A
0N/A// Update the flags to indicate the presence of these optional fields.
0N/Avoid constMethodOopDesc::set_inlined_tables_length(
0N/A 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 // Must be done in the order below, otherwise length_addr accessors
0N/A // will not work. Only set bit in header if length is positive.
0N/A assert(_flags == 0, "Error");
0N/A if (compressed_line_number_size > 0) {
0N/A _flags |= _has_linenumber_table;
0N/A }
0N/A if (checked_exceptions_len > 0) {
0N/A _flags |= _has_checked_exceptions;
0N/A *(checked_exceptions_length_addr()) = checked_exceptions_len;
0N/A }
3879N/A if (exception_table_len > 0) {
3879N/A _flags |= _has_exception_table;
3879N/A *(exception_table_length_addr()) = exception_table_len;
3879N/A }
0N/A if (localvariable_table_len > 0) {
0N/A _flags |= _has_localvariable_table;
0N/A *(localvariable_table_length_addr()) = localvariable_table_len;
0N/A }
0N/A}
0N/A
0N/A
0N/Aint constMethodOopDesc::checked_exceptions_length() const {
0N/A return has_checked_exceptions() ? *(checked_exceptions_length_addr()) : 0;
0N/A}
0N/A
0N/A
0N/ACheckedExceptionElement* constMethodOopDesc::checked_exceptions_start() const {
0N/A u2* addr = checked_exceptions_length_addr();
0N/A u2 length = *addr;
0N/A assert(length > 0, "should only be called if table is present");
0N/A addr -= length * sizeof(CheckedExceptionElement) / sizeof(u2);
0N/A return (CheckedExceptionElement*) addr;
0N/A}
0N/A
0N/A
0N/Aint constMethodOopDesc::localvariable_table_length() const {
0N/A return has_localvariable_table() ? *(localvariable_table_length_addr()) : 0;
0N/A}
0N/A
0N/A
0N/ALocalVariableTableElement* constMethodOopDesc::localvariable_table_start() const {
0N/A u2* addr = localvariable_table_length_addr();
0N/A u2 length = *addr;
0N/A assert(length > 0, "should only be called if table is present");
0N/A addr -= length * sizeof(LocalVariableTableElement) / sizeof(u2);
0N/A return (LocalVariableTableElement*) addr;
0N/A}
3879N/A
3879N/Aint constMethodOopDesc::exception_table_length() const {
3879N/A return has_exception_handler() ? *(exception_table_length_addr()) : 0;
3879N/A}
3879N/A
3879N/AExceptionTableElement* constMethodOopDesc::exception_table_start() const {
3879N/A u2* addr = exception_table_length_addr();
3879N/A u2 length = *addr;
3879N/A assert(length > 0, "should only be called if table is present");
3879N/A addr -= length * sizeof(ExceptionTableElement) / sizeof(u2);
3879N/A return (ExceptionTableElement*)addr;
3879N/A}