You need to sign in or sign up before continuing.
constMethodOop.cpp 6.4 KB
Newer Older
D
duke 已提交
1
/*
2
 * Copyright (c) 2003, 2012, Oracle and/or its affiliates. All rights reserved.
D
duke 已提交
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 *
 * This code is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License version 2 only, as
 * published by the Free Software Foundation.
 *
 * This code is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 * version 2 for more details (a copy is included in the LICENSE file that
 * accompanied this code).
 *
 * You should have received a copy of the GNU General Public License version
 * 2 along with this work; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 *
19 20 21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 * or visit www.oracle.com if you need additional information or have any
 * questions.
D
duke 已提交
22 23 24
 *
 */

25 26 27
#include "precompiled.hpp"
#include "oops/constMethodOop.hpp"
#include "oops/methodOop.hpp"
D
duke 已提交
28 29 30 31 32 33 34 35 36 37

// Static initialization
const u2 constMethodOopDesc::MAX_IDNUM   = 0xFFFE;
const u2 constMethodOopDesc::UNSET_IDNUM = 0xFFFF;

// How big must this constMethodObject be?

int constMethodOopDesc::object_size(int code_size,
                                    int compressed_line_number_size,
                                    int local_variable_table_length,
38
                                    int exception_table_length,
D
duke 已提交
39 40 41 42 43 44 45 46 47 48 49 50 51 52
                                    int checked_exceptions_length) {
  int extra_bytes = code_size;
  if (compressed_line_number_size > 0) {
    extra_bytes += compressed_line_number_size;
  }
  if (checked_exceptions_length > 0) {
    extra_bytes += sizeof(u2);
    extra_bytes += checked_exceptions_length * sizeof(CheckedExceptionElement);
  }
  if (local_variable_table_length > 0) {
    extra_bytes += sizeof(u2);
    extra_bytes +=
              local_variable_table_length * sizeof(LocalVariableTableElement);
  }
53 54 55 56
  if (exception_table_length > 0) {
    extra_bytes += sizeof(u2);
    extra_bytes += exception_table_length * sizeof(ExceptionTableElement);
  }
D
duke 已提交
57 58 59 60
  int extra_words = align_size_up(extra_bytes, BytesPerWord) / BytesPerWord;
  return align_object_size(header_size() + extra_words);
}

61 62 63 64
methodOop constMethodOopDesc::method() const {
    return instanceKlass::cast(_constants->pool_holder())->method_with_idnum(
                               _method_idnum);
  }
D
duke 已提交
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80

// linenumber table - note that length is unknown until decompression,
// see class CompressedLineNumberReadStream.

u_char* constMethodOopDesc::compressed_linenumber_table() const {
  // Located immediately following the bytecodes.
  assert(has_linenumber_table(), "called only if table is present");
  return code_end();
}

u2* constMethodOopDesc::checked_exceptions_length_addr() const {
  // Located at the end of the constMethod.
  assert(has_checked_exceptions(), "called only if table is present");
  return last_u2_element();
}

81 82
u2* constMethodOopDesc::exception_table_length_addr() const {
  assert(has_exception_handler(), "called only if table is present");
D
duke 已提交
83 84 85 86
  if (has_checked_exceptions()) {
    // If checked_exception present, locate immediately before them.
    return (u2*) checked_exceptions_start() - 1;
  } else {
87
    // Else, the exception table is at the end of the constMethod.
D
duke 已提交
88 89 90 91
    return last_u2_element();
  }
}

92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107
u2* constMethodOopDesc::localvariable_table_length_addr() const {
  assert(has_localvariable_table(), "called only if table is present");
  if (has_exception_handler()) {
    // If exception_table present, locate immediately before them.
    return (u2*) exception_table_start() - 1;
  } else {
    if (has_checked_exceptions()) {
      // If checked_exception present, locate immediately before them.
      return (u2*) checked_exceptions_start() - 1;
    } else {
      // Else, the linenumber table is at the end of the constMethod.
      return last_u2_element();
    }
  }
}

D
duke 已提交
108 109 110 111 112

// Update the flags to indicate the presence of these optional fields.
void constMethodOopDesc::set_inlined_tables_length(
                                              int checked_exceptions_len,
                                              int compressed_line_number_size,
113 114
                                              int localvariable_table_len,
                                              int exception_table_len) {
D
duke 已提交
115 116 117 118 119 120 121 122 123 124
  // Must be done in the order below, otherwise length_addr accessors
  // will not work. Only set bit in header if length is positive.
  assert(_flags == 0, "Error");
  if (compressed_line_number_size > 0) {
    _flags |= _has_linenumber_table;
  }
  if (checked_exceptions_len > 0) {
    _flags |= _has_checked_exceptions;
    *(checked_exceptions_length_addr()) = checked_exceptions_len;
  }
125 126 127 128
  if (exception_table_len > 0) {
    _flags |= _has_exception_table;
    *(exception_table_length_addr()) = exception_table_len;
  }
D
duke 已提交
129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161
  if (localvariable_table_len > 0) {
    _flags |= _has_localvariable_table;
    *(localvariable_table_length_addr()) = localvariable_table_len;
  }
}


int constMethodOopDesc::checked_exceptions_length() const {
  return has_checked_exceptions() ? *(checked_exceptions_length_addr()) : 0;
}


CheckedExceptionElement* constMethodOopDesc::checked_exceptions_start() const {
  u2* addr = checked_exceptions_length_addr();
  u2 length = *addr;
  assert(length > 0, "should only be called if table is present");
  addr -= length * sizeof(CheckedExceptionElement) / sizeof(u2);
  return (CheckedExceptionElement*) addr;
}


int constMethodOopDesc::localvariable_table_length() const {
  return has_localvariable_table() ? *(localvariable_table_length_addr()) : 0;
}


LocalVariableTableElement* constMethodOopDesc::localvariable_table_start() const {
  u2* addr = localvariable_table_length_addr();
  u2 length = *addr;
  assert(length > 0, "should only be called if table is present");
  addr -= length * sizeof(LocalVariableTableElement) / sizeof(u2);
  return (LocalVariableTableElement*) addr;
}
162 163 164 165 166 167 168 169 170 171 172 173

int constMethodOopDesc::exception_table_length() const {
  return has_exception_handler() ? *(exception_table_length_addr()) : 0;
}

ExceptionTableElement* constMethodOopDesc::exception_table_start() const {
  u2* addr = exception_table_length_addr();
  u2 length = *addr;
  assert(length > 0, "should only be called if table is present");
  addr -= length * sizeof(ExceptionTableElement) / sizeof(u2);
  return (ExceptionTableElement*)addr;
}