hotspot/src/share/vm/oops/constMethodOop.cpp
author brutisso
Tue, 28 Jun 2011 14:23:27 +0200
changeset 10002 2d83be3a0927
parent 7397 5b173b4ca846
child 12937 0032fb2caff6
permissions -rw-r--r--
7016112: CMS: crash during promotion testing Summary: Also reviewed by mikael.gerdin@oracle.com; stdlib:qsort() does byte-by-byte swapping on Windows. This leads to pointer shearing. Fix is to implement a quicksort that does full pointer updates. Reviewed-by: never, coleenp, ysr
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
     2
 * Copyright (c) 2003, 2010, 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
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
// linenumber table - note that length is unknown until decompression,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
// see class CompressedLineNumberReadStream.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
u_char* constMethodOopDesc::compressed_linenumber_table() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
  // Located immediately following the bytecodes.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
  assert(has_linenumber_table(), "called only if table is present");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
  return code_end();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
u2* constMethodOopDesc::checked_exceptions_length_addr() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
  // Located at the end of the constMethod.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
  assert(has_checked_exceptions(), "called only if table is present");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
  return last_u2_element();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
u2* constMethodOopDesc::localvariable_table_length_addr() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
  assert(has_localvariable_table(), "called only if table is present");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
  if (has_checked_exceptions()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
    // If checked_exception present, locate immediately before them.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
    return (u2*) checked_exceptions_start() - 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
    // Else, the linenumber table is at the end of the constMethod.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
    return last_u2_element();
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
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
// Update the flags to indicate the presence of these optional fields.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
void constMethodOopDesc::set_inlined_tables_length(
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
                                              int checked_exceptions_len,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
                                              int compressed_line_number_size,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
                                              int localvariable_table_len) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
  // Must be done in the order below, otherwise length_addr accessors
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
  // will not work. Only set bit in header if length is positive.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
  assert(_flags == 0, "Error");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
  if (compressed_line_number_size > 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
    _flags |= _has_linenumber_table;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
  if (checked_exceptions_len > 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
    _flags |= _has_checked_exceptions;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
    *(checked_exceptions_length_addr()) = checked_exceptions_len;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
  if (localvariable_table_len > 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
    _flags |= _has_localvariable_table;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
    *(localvariable_table_length_addr()) = localvariable_table_len;
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
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
int constMethodOopDesc::checked_exceptions_length() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
  return has_checked_exceptions() ? *(checked_exceptions_length_addr()) : 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
CheckedExceptionElement* constMethodOopDesc::checked_exceptions_start() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
  u2* addr = checked_exceptions_length_addr();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
  u2 length = *addr;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
  assert(length > 0, "should only be called if table is present");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
  addr -= length * sizeof(CheckedExceptionElement) / sizeof(u2);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
  return (CheckedExceptionElement*) addr;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
int constMethodOopDesc::localvariable_table_length() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
  return has_localvariable_table() ? *(localvariable_table_length_addr()) : 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
LocalVariableTableElement* constMethodOopDesc::localvariable_table_start() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
  u2* addr = localvariable_table_length_addr();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
  u2 length = *addr;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
  assert(length > 0, "should only be called if table is present");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
  addr -= length * sizeof(LocalVariableTableElement) / sizeof(u2);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
  return (LocalVariableTableElement*) addr;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
}