hotspot/src/share/vm/oops/constMethodOop.cpp
author xlu
Mon, 06 Apr 2009 15:47:39 -0700
changeset 2526 39a58a50be35
parent 1 489c9b5090e2
child 5547 f4b087cbb361
permissions -rw-r--r--
6699669: Hotspot server leaves synchronized block with monitor in bad state Summary: Remove usage of _highest_lock field in Thread so that is_lock_owned won't depend on the correct update of that field. Reviewed-by: never, dice, acorn
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
489c9b5090e2 Initial load
duke
parents:
diff changeset
     2
 * Copyright 2003-2006 Sun Microsystems, Inc.  All Rights Reserved.
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
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    19
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    20
 * CA 95054 USA or visit www.sun.com if you need additional information or
489c9b5090e2 Initial load
duke
parents:
diff changeset
    21
 * have any questions.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    22
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    23
 */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    24
489c9b5090e2 Initial load
duke
parents:
diff changeset
    25
# include "incls/_precompiled.incl"
489c9b5090e2 Initial load
duke
parents:
diff changeset
    26
# include "incls/_constMethodOop.cpp.incl"
489c9b5090e2 Initial load
duke
parents:
diff changeset
    27
489c9b5090e2 Initial load
duke
parents:
diff changeset
    28
// Static initialization
489c9b5090e2 Initial load
duke
parents:
diff changeset
    29
const u2 constMethodOopDesc::MAX_IDNUM   = 0xFFFE;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    30
const u2 constMethodOopDesc::UNSET_IDNUM = 0xFFFF;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    31
489c9b5090e2 Initial load
duke
parents:
diff changeset
    32
// How big must this constMethodObject be?
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
int constMethodOopDesc::object_size(int code_size,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
                                    int compressed_line_number_size,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
                                    int local_variable_table_length,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
                                    int checked_exceptions_length) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
  int extra_bytes = code_size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
  if (compressed_line_number_size > 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
    extra_bytes += compressed_line_number_size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
  if (checked_exceptions_length > 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
    extra_bytes += sizeof(u2);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
    extra_bytes += checked_exceptions_length * sizeof(CheckedExceptionElement);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
  if (local_variable_table_length > 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
    extra_bytes += sizeof(u2);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
    extra_bytes +=
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
              local_variable_table_length * sizeof(LocalVariableTableElement);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
  int extra_words = align_size_up(extra_bytes, BytesPerWord) / BytesPerWord;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
  return align_object_size(header_size() + extra_words);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
// linenumber table - note that length is unknown until decompression,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
// see class CompressedLineNumberReadStream.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
u_char* constMethodOopDesc::compressed_linenumber_table() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
  // Located immediately following the bytecodes.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
  assert(has_linenumber_table(), "called only if table is present");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
  return code_end();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
u2* constMethodOopDesc::checked_exceptions_length_addr() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
  // Located at the end of the constMethod.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
  assert(has_checked_exceptions(), "called only if table is present");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
  return last_u2_element();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
u2* constMethodOopDesc::localvariable_table_length_addr() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
  assert(has_localvariable_table(), "called only if table is present");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
  if (has_checked_exceptions()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
    // If checked_exception present, locate immediately before them.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
    return (u2*) checked_exceptions_start() - 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
    // Else, the linenumber table is at the end of the constMethod.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
    return last_u2_element();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
// Update the flags to indicate the presence of these optional fields.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
void constMethodOopDesc::set_inlined_tables_length(
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
                                              int checked_exceptions_len,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
                                              int compressed_line_number_size,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
                                              int localvariable_table_len) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
  // Must be done in the order below, otherwise length_addr accessors
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
  // will not work. Only set bit in header if length is positive.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
  assert(_flags == 0, "Error");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
  if (compressed_line_number_size > 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
    _flags |= _has_linenumber_table;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
  if (checked_exceptions_len > 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
    _flags |= _has_checked_exceptions;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
    *(checked_exceptions_length_addr()) = checked_exceptions_len;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
  if (localvariable_table_len > 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
    _flags |= _has_localvariable_table;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
    *(localvariable_table_length_addr()) = localvariable_table_len;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
int constMethodOopDesc::checked_exceptions_length() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
  return has_checked_exceptions() ? *(checked_exceptions_length_addr()) : 0;
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
CheckedExceptionElement* constMethodOopDesc::checked_exceptions_start() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
  u2* addr = checked_exceptions_length_addr();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
  u2 length = *addr;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
  assert(length > 0, "should only be called if table is present");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
  addr -= length * sizeof(CheckedExceptionElement) / sizeof(u2);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
  return (CheckedExceptionElement*) addr;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
int constMethodOopDesc::localvariable_table_length() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
  return has_localvariable_table() ? *(localvariable_table_length_addr()) : 0;
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
LocalVariableTableElement* constMethodOopDesc::localvariable_table_start() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
  u2* addr = localvariable_table_length_addr();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
  u2 length = *addr;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
  assert(length > 0, "should only be called if table is present");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
  addr -= length * sizeof(LocalVariableTableElement) / sizeof(u2);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
  return (LocalVariableTableElement*) addr;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
}