hotspot/src/share/vm/oops/constMethodOop.cpp
author jiangli
Wed, 06 Jun 2012 14:33:43 -0400
changeset 12937 0032fb2caff6
parent 7397 5b173b4ca846
child 13282 9872915dd78d
permissions -rw-r--r--
7172967: Eliminate constMethod's _method backpointer to methodOop. Summary: Eliminate constMethod's _method backpointer to methodOop, and move the _constant field from methodOop to constMethod. Reviewed-by: roland, bdelsart, kamg
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
12937
0032fb2caff6 7172967: Eliminate constMethod's _method backpointer to methodOop.
jiangli
parents: 7397
diff changeset
     2
 * Copyright (c) 2003, 2012, Oracle and/or its affiliates. All rights reserved.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     4
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
489c9b5090e2 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
489c9b5090e2 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     8
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
489c9b5090e2 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
489c9b5090e2 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
489c9b5090e2 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
489c9b5090e2 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
489c9b5090e2 Initial load
duke
parents:
diff changeset
    14
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
489c9b5090e2 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    18
 *
5547
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1
diff changeset
    21
 * questions.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    22
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    23
 */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    24
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    25
#include "precompiled.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    26
#include "oops/constMethodOop.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    27
#include "oops/methodOop.hpp"
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    28
489c9b5090e2 Initial load
duke
parents:
diff changeset
    29
// Static initialization
489c9b5090e2 Initial load
duke
parents:
diff changeset
    30
const u2 constMethodOopDesc::MAX_IDNUM   = 0xFFFE;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    31
const u2 constMethodOopDesc::UNSET_IDNUM = 0xFFFF;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    32
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
// How big must this constMethodObject be?
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
int constMethodOopDesc::object_size(int code_size,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
                                    int compressed_line_number_size,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
                                    int local_variable_table_length,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
                                    int checked_exceptions_length) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
  int extra_bytes = code_size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
  if (compressed_line_number_size > 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
    extra_bytes += compressed_line_number_size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
  if (checked_exceptions_length > 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
    extra_bytes += sizeof(u2);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
    extra_bytes += checked_exceptions_length * sizeof(CheckedExceptionElement);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
  if (local_variable_table_length > 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
    extra_bytes += sizeof(u2);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
    extra_bytes +=
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
              local_variable_table_length * sizeof(LocalVariableTableElement);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
  int extra_words = align_size_up(extra_bytes, BytesPerWord) / BytesPerWord;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
  return align_object_size(header_size() + extra_words);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
12937
0032fb2caff6 7172967: Eliminate constMethod's _method backpointer to methodOop.
jiangli
parents: 7397
diff changeset
    56
methodOop constMethodOopDesc::method() const {
0032fb2caff6 7172967: Eliminate constMethod's _method backpointer to methodOop.
jiangli
parents: 7397
diff changeset
    57
    return instanceKlass::cast(_constants->pool_holder())->method_with_idnum(
0032fb2caff6 7172967: Eliminate constMethod's _method backpointer to methodOop.
jiangli
parents: 7397
diff changeset
    58
                               _method_idnum);
0032fb2caff6 7172967: Eliminate constMethod's _method backpointer to methodOop.
jiangli
parents: 7397
diff changeset
    59
  }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
// linenumber table - note that length is unknown until decompression,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
// see class CompressedLineNumberReadStream.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
u_char* constMethodOopDesc::compressed_linenumber_table() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
  // Located immediately following the bytecodes.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
  assert(has_linenumber_table(), "called only if table is present");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
  return code_end();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
u2* constMethodOopDesc::checked_exceptions_length_addr() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
  // Located at the end of the constMethod.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
  assert(has_checked_exceptions(), "called only if table is present");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
  return last_u2_element();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
u2* constMethodOopDesc::localvariable_table_length_addr() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
  assert(has_localvariable_table(), "called only if table is present");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
  if (has_checked_exceptions()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
    // If checked_exception present, locate immediately before them.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
    return (u2*) checked_exceptions_start() - 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
    // Else, the linenumber table is at the end of the constMethod.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
    return last_u2_element();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
// Update the flags to indicate the presence of these optional fields.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
void constMethodOopDesc::set_inlined_tables_length(
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
                                              int checked_exceptions_len,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
                                              int compressed_line_number_size,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
                                              int localvariable_table_len) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
  // Must be done in the order below, otherwise length_addr accessors
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
  // will not work. Only set bit in header if length is positive.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
  assert(_flags == 0, "Error");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
  if (compressed_line_number_size > 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
    _flags |= _has_linenumber_table;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
  if (checked_exceptions_len > 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
    _flags |= _has_checked_exceptions;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
    *(checked_exceptions_length_addr()) = checked_exceptions_len;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
  if (localvariable_table_len > 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
    _flags |= _has_localvariable_table;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
    *(localvariable_table_length_addr()) = localvariable_table_len;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
int constMethodOopDesc::checked_exceptions_length() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
  return has_checked_exceptions() ? *(checked_exceptions_length_addr()) : 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
CheckedExceptionElement* constMethodOopDesc::checked_exceptions_start() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
  u2* addr = checked_exceptions_length_addr();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
  u2 length = *addr;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
  assert(length > 0, "should only be called if table is present");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
  addr -= length * sizeof(CheckedExceptionElement) / sizeof(u2);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
  return (CheckedExceptionElement*) addr;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
int constMethodOopDesc::localvariable_table_length() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
  return has_localvariable_table() ? *(localvariable_table_length_addr()) : 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
LocalVariableTableElement* constMethodOopDesc::localvariable_table_start() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
  u2* addr = localvariable_table_length_addr();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
  u2 length = *addr;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
  assert(length > 0, "should only be called if table is present");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
  addr -= length * sizeof(LocalVariableTableElement) / sizeof(u2);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
  return (LocalVariableTableElement*) addr;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
}