src/share/vm/oops/constMethodOop.cpp

Sat, 01 May 2010 02:42:18 -0700

author
jrose
date
Sat, 01 May 2010 02:42:18 -0700
changeset 1862
cd5dbf694d45
parent 435
a61af66fc99e
child 1907
c18cbe5936b8
permissions
-rw-r--r--

6939134: JSR 292 adjustments to method handle invocation
Summary: split MethodHandle.invoke into invokeExact and invokeGeneric; also clean up JVM-to-Java interfaces
Reviewed-by: twisti

duke@435 1 /*
duke@435 2 * Copyright 2003-2006 Sun Microsystems, Inc. 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 *
duke@435 19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
duke@435 20 * CA 95054 USA or visit www.sun.com if you need additional information or
duke@435 21 * have any questions.
duke@435 22 *
duke@435 23 */
duke@435 24
duke@435 25 # include "incls/_precompiled.incl"
duke@435 26 # include "incls/_constMethodOop.cpp.incl"
duke@435 27
duke@435 28 // Static initialization
duke@435 29 const u2 constMethodOopDesc::MAX_IDNUM = 0xFFFE;
duke@435 30 const u2 constMethodOopDesc::UNSET_IDNUM = 0xFFFF;
duke@435 31
duke@435 32 // How big must this constMethodObject be?
duke@435 33
duke@435 34 int constMethodOopDesc::object_size(int code_size,
duke@435 35 int compressed_line_number_size,
duke@435 36 int local_variable_table_length,
duke@435 37 int checked_exceptions_length) {
duke@435 38 int extra_bytes = code_size;
duke@435 39 if (compressed_line_number_size > 0) {
duke@435 40 extra_bytes += compressed_line_number_size;
duke@435 41 }
duke@435 42 if (checked_exceptions_length > 0) {
duke@435 43 extra_bytes += sizeof(u2);
duke@435 44 extra_bytes += checked_exceptions_length * sizeof(CheckedExceptionElement);
duke@435 45 }
duke@435 46 if (local_variable_table_length > 0) {
duke@435 47 extra_bytes += sizeof(u2);
duke@435 48 extra_bytes +=
duke@435 49 local_variable_table_length * sizeof(LocalVariableTableElement);
duke@435 50 }
duke@435 51 int extra_words = align_size_up(extra_bytes, BytesPerWord) / BytesPerWord;
duke@435 52 return align_object_size(header_size() + extra_words);
duke@435 53 }
duke@435 54
duke@435 55
duke@435 56 // linenumber table - note that length is unknown until decompression,
duke@435 57 // see class CompressedLineNumberReadStream.
duke@435 58
duke@435 59 u_char* constMethodOopDesc::compressed_linenumber_table() const {
duke@435 60 // Located immediately following the bytecodes.
duke@435 61 assert(has_linenumber_table(), "called only if table is present");
duke@435 62 return code_end();
duke@435 63 }
duke@435 64
duke@435 65 u2* constMethodOopDesc::checked_exceptions_length_addr() const {
duke@435 66 // Located at the end of the constMethod.
duke@435 67 assert(has_checked_exceptions(), "called only if table is present");
duke@435 68 return last_u2_element();
duke@435 69 }
duke@435 70
duke@435 71 u2* constMethodOopDesc::localvariable_table_length_addr() const {
duke@435 72 assert(has_localvariable_table(), "called only if table is present");
duke@435 73 if (has_checked_exceptions()) {
duke@435 74 // If checked_exception present, locate immediately before them.
duke@435 75 return (u2*) checked_exceptions_start() - 1;
duke@435 76 } else {
duke@435 77 // Else, the linenumber table is at the end of the constMethod.
duke@435 78 return last_u2_element();
duke@435 79 }
duke@435 80 }
duke@435 81
duke@435 82
duke@435 83 // Update the flags to indicate the presence of these optional fields.
duke@435 84 void constMethodOopDesc::set_inlined_tables_length(
duke@435 85 int checked_exceptions_len,
duke@435 86 int compressed_line_number_size,
duke@435 87 int localvariable_table_len) {
duke@435 88 // Must be done in the order below, otherwise length_addr accessors
duke@435 89 // will not work. Only set bit in header if length is positive.
duke@435 90 assert(_flags == 0, "Error");
duke@435 91 if (compressed_line_number_size > 0) {
duke@435 92 _flags |= _has_linenumber_table;
duke@435 93 }
duke@435 94 if (checked_exceptions_len > 0) {
duke@435 95 _flags |= _has_checked_exceptions;
duke@435 96 *(checked_exceptions_length_addr()) = checked_exceptions_len;
duke@435 97 }
duke@435 98 if (localvariable_table_len > 0) {
duke@435 99 _flags |= _has_localvariable_table;
duke@435 100 *(localvariable_table_length_addr()) = localvariable_table_len;
duke@435 101 }
duke@435 102 }
duke@435 103
duke@435 104
duke@435 105 int constMethodOopDesc::checked_exceptions_length() const {
duke@435 106 return has_checked_exceptions() ? *(checked_exceptions_length_addr()) : 0;
duke@435 107 }
duke@435 108
duke@435 109
duke@435 110 CheckedExceptionElement* constMethodOopDesc::checked_exceptions_start() const {
duke@435 111 u2* addr = checked_exceptions_length_addr();
duke@435 112 u2 length = *addr;
duke@435 113 assert(length > 0, "should only be called if table is present");
duke@435 114 addr -= length * sizeof(CheckedExceptionElement) / sizeof(u2);
duke@435 115 return (CheckedExceptionElement*) addr;
duke@435 116 }
duke@435 117
duke@435 118
duke@435 119 int constMethodOopDesc::localvariable_table_length() const {
duke@435 120 return has_localvariable_table() ? *(localvariable_table_length_addr()) : 0;
duke@435 121 }
duke@435 122
duke@435 123
duke@435 124 LocalVariableTableElement* constMethodOopDesc::localvariable_table_start() const {
duke@435 125 u2* addr = localvariable_table_length_addr();
duke@435 126 u2 length = *addr;
duke@435 127 assert(length > 0, "should only be called if table is present");
duke@435 128 addr -= length * sizeof(LocalVariableTableElement) / sizeof(u2);
duke@435 129 return (LocalVariableTableElement*) addr;
duke@435 130 }

mercurial