hotspot/src/share/vm/runtime/relocator.hpp
author never
Thu, 13 Jan 2011 22:15:41 -0800
changeset 7913 dd096a83bdbb
parent 7397 5b173b4ca846
child 7917 5c35c053175b
permissions -rw-r--r--
4926272: methodOopDesc::method_from_bcp is unsafe Reviewed-by: coleenp, jrose, kvn, dcubed
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
7913
dd096a83bdbb 4926272: methodOopDesc::method_from_bcp is unsafe
never
parents: 7397
diff changeset
     2
 * Copyright (c) 1997, 2011, 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: 6974
diff changeset
    25
#ifndef SHARE_VM_RUNTIME_RELOCATOR_HPP
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6974
diff changeset
    26
#define SHARE_VM_RUNTIME_RELOCATOR_HPP
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6974
diff changeset
    27
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6974
diff changeset
    28
#include "interpreter/bytecodes.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6974
diff changeset
    29
#include "oops/methodOop.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6974
diff changeset
    30
#ifdef TARGET_ARCH_x86
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6974
diff changeset
    31
# include "bytes_x86.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6974
diff changeset
    32
#endif
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6974
diff changeset
    33
#ifdef TARGET_ARCH_sparc
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6974
diff changeset
    34
# include "bytes_sparc.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6974
diff changeset
    35
#endif
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6974
diff changeset
    36
#ifdef TARGET_ARCH_zero
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6974
diff changeset
    37
# include "bytes_zero.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6974
diff changeset
    38
#endif
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6974
diff changeset
    39
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
// This code has been converted from the 1.1E java virtual machine
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
// Thanks to the JavaTopics group for using the code
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
class ChangeItem;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
// Callback object for code relocations
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
class RelocatorListener : public StackObj {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
  RelocatorListener() {};
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
  virtual void relocated(int bci, int delta, int new_method_size) = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
class Relocator : public ResourceObj {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
  Relocator(methodHandle method, RelocatorListener* listener);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
  methodHandle insert_space_at(int bci, int space, u_char inst_buffer[], TRAPS);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
  // Callbacks from ChangeItem's
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
  bool handle_code_changes();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
  bool handle_widen       (int bci, int new_ilen, u_char inst_buffer[]);  // handles general instructions
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
  void push_jump_widen  (int bci, int delta, int new_delta);    // pushes jumps
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
  bool handle_jump_widen  (int bci, int delta);     // handles jumps
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
  bool handle_switch_pad  (int bci, int old_pad, bool is_lookup_switch); // handles table and lookup switches
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
 private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
  unsigned char* _code_array;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
  int            _code_array_length;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
  int            _code_length;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
  unsigned char* _compressed_line_number_table;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
  int            _compressed_line_number_table_size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
  methodHandle   _method;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
  u_char         _overwrite[3];             // stores overwritten bytes for shrunken instructions
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
  GrowableArray<ChangeItem*>* _changes;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
  unsigned char* code_array() const         { return _code_array; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
  void set_code_array(unsigned char* array) { _code_array = array; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
  int code_length() const                   { return _code_length; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
  void set_code_length(int length)          { _code_length = length; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
  int code_array_length() const             { return _code_array_length; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
  void set_code_array_length(int length)    { _code_array_length = length; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
  unsigned char* compressed_line_number_table() const         { return _compressed_line_number_table; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
  void set_compressed_line_number_table(unsigned char* table) { _compressed_line_number_table = table; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
  int compressed_line_number_table_size() const               { return _compressed_line_number_table_size; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
  void set_compressed_line_number_table_size(int size)        { _compressed_line_number_table_size = size; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
  methodHandle method() const               { return _method; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
  void set_method(methodHandle method)      { _method = method; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
  // This will return a raw bytecode, which is possibly rewritten.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
  Bytecodes::Code code_at(int bci) const          { return (Bytecodes::Code) code_array()[bci]; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
  void code_at_put(int bci, Bytecodes::Code code) { code_array()[bci] = (char) code; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
  // get and set signed integers in the code_array
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
  inline int   int_at(int bci) const               { return Bytes::get_Java_u4(&code_array()[bci]); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
  inline void  int_at_put(int bci, int value)      { Bytes::put_Java_u4(&code_array()[bci], value); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
  // get and set signed shorts in the code_array
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
  inline short short_at(int bci) const            { return (short)Bytes::get_Java_u2(&code_array()[bci]); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
  inline void  short_at_put(int bci, short value) { Bytes::put_Java_u2((address) &code_array()[bci], value); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
  // get the address of in the code_array
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
  inline char* addr_at(int bci) const             { return (char*) &code_array()[bci]; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
7913
dd096a83bdbb 4926272: methodOopDesc::method_from_bcp is unsafe
never
parents: 7397
diff changeset
   109
  int  instruction_length_at(int bci)             { return Bytecodes::length_at(_method(), code_array() + bci); }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
  // Helper methods
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
  int  align(int n) const                          { return (n+3) & ~3; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
  int  code_slop_pct() const                       { return 25; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
  bool is_opcode_lookupswitch(Bytecodes::Code bc);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
  // basic relocation methods
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
  bool relocate_code         (int bci, int ilen, int delta);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
  void change_jumps          (int break_bci, int delta);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
  void change_jump           (int bci, int offset, bool is_short, int break_bci, int delta);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
  void adjust_exception_table(int bci, int delta);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
  void adjust_line_no_table  (int bci, int delta);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
  void adjust_local_var_table(int bci, int delta);
6974
a013f1c533a5 6991315: RedefineClasses fails with java.lang.VerifyError
kamg
parents: 5547
diff changeset
   123
  void adjust_stack_map_table(int bci, int delta);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
  int  get_orig_switch_pad   (int bci, bool is_lookup_switch);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
  int  rc_instr_len          (int bci);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
  bool expand_code_array     (int delta);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
  // Callback support
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
  RelocatorListener *_listener;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
  void notify(int bci, int delta, int new_code_length) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
    if (_listener != NULL)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
      _listener->relocated(bci, delta, new_code_length);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
};
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6974
diff changeset
   135
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6974
diff changeset
   136
#endif // SHARE_VM_RUNTIME_RELOCATOR_HPP