src/share/vm/runtime/relocator.hpp

Thu, 21 Oct 2010 10:10:23 -0400

author
kamg
date
Thu, 21 Oct 2010 10:10:23 -0400
changeset 2232
a4c7fe54bf3f
parent 1907
c18cbe5936b8
child 2314
f95d63e2154a
permissions
-rw-r--r--

6991315: RedefineClasses fails with java.lang.VerifyError
Summary: Repair stackmap table attribute when relocating bytecode
Reviewed-by: acorn, never

duke@435 1 /*
trims@1907 2 * Copyright (c) 1997, 2004, Oracle and/or its affiliates. All rights reserved.
duke@435 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
duke@435 4 *
duke@435 5 * This code is free software; you can redistribute it and/or modify it
duke@435 6 * under the terms of the GNU General Public License version 2 only, as
duke@435 7 * published by the Free Software Foundation.
duke@435 8 *
duke@435 9 * This code is distributed in the hope that it will be useful, but WITHOUT
duke@435 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
duke@435 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
duke@435 12 * version 2 for more details (a copy is included in the LICENSE file that
duke@435 13 * accompanied this code).
duke@435 14 *
duke@435 15 * You should have received a copy of the GNU General Public License version
duke@435 16 * 2 along with this work; if not, write to the Free Software Foundation,
duke@435 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
duke@435 18 *
trims@1907 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
trims@1907 20 * or visit www.oracle.com if you need additional information or have any
trims@1907 21 * questions.
duke@435 22 *
duke@435 23 */
duke@435 24
duke@435 25 // This code has been converted from the 1.1E java virtual machine
duke@435 26 // Thanks to the JavaTopics group for using the code
duke@435 27
duke@435 28 class ChangeItem;
duke@435 29
duke@435 30 // Callback object for code relocations
duke@435 31 class RelocatorListener : public StackObj {
duke@435 32 public:
duke@435 33 RelocatorListener() {};
duke@435 34 virtual void relocated(int bci, int delta, int new_method_size) = 0;
duke@435 35 };
duke@435 36
duke@435 37
duke@435 38 class Relocator : public ResourceObj {
duke@435 39 public:
duke@435 40 Relocator(methodHandle method, RelocatorListener* listener);
duke@435 41 methodHandle insert_space_at(int bci, int space, u_char inst_buffer[], TRAPS);
duke@435 42
duke@435 43 // Callbacks from ChangeItem's
duke@435 44 bool handle_code_changes();
duke@435 45 bool handle_widen (int bci, int new_ilen, u_char inst_buffer[]); // handles general instructions
duke@435 46 void push_jump_widen (int bci, int delta, int new_delta); // pushes jumps
duke@435 47 bool handle_jump_widen (int bci, int delta); // handles jumps
duke@435 48 bool handle_switch_pad (int bci, int old_pad, bool is_lookup_switch); // handles table and lookup switches
duke@435 49
duke@435 50 private:
duke@435 51 unsigned char* _code_array;
duke@435 52 int _code_array_length;
duke@435 53 int _code_length;
duke@435 54 unsigned char* _compressed_line_number_table;
duke@435 55 int _compressed_line_number_table_size;
duke@435 56 methodHandle _method;
duke@435 57 u_char _overwrite[3]; // stores overwritten bytes for shrunken instructions
duke@435 58
duke@435 59 GrowableArray<ChangeItem*>* _changes;
duke@435 60
duke@435 61 unsigned char* code_array() const { return _code_array; }
duke@435 62 void set_code_array(unsigned char* array) { _code_array = array; }
duke@435 63
duke@435 64 int code_length() const { return _code_length; }
duke@435 65 void set_code_length(int length) { _code_length = length; }
duke@435 66
duke@435 67 int code_array_length() const { return _code_array_length; }
duke@435 68 void set_code_array_length(int length) { _code_array_length = length; }
duke@435 69
duke@435 70 unsigned char* compressed_line_number_table() const { return _compressed_line_number_table; }
duke@435 71 void set_compressed_line_number_table(unsigned char* table) { _compressed_line_number_table = table; }
duke@435 72
duke@435 73 int compressed_line_number_table_size() const { return _compressed_line_number_table_size; }
duke@435 74 void set_compressed_line_number_table_size(int size) { _compressed_line_number_table_size = size; }
duke@435 75
duke@435 76 methodHandle method() const { return _method; }
duke@435 77 void set_method(methodHandle method) { _method = method; }
duke@435 78
duke@435 79 // This will return a raw bytecode, which is possibly rewritten.
duke@435 80 Bytecodes::Code code_at(int bci) const { return (Bytecodes::Code) code_array()[bci]; }
duke@435 81 void code_at_put(int bci, Bytecodes::Code code) { code_array()[bci] = (char) code; }
duke@435 82
duke@435 83 // get and set signed integers in the code_array
duke@435 84 inline int int_at(int bci) const { return Bytes::get_Java_u4(&code_array()[bci]); }
duke@435 85 inline void int_at_put(int bci, int value) { Bytes::put_Java_u4(&code_array()[bci], value); }
duke@435 86
duke@435 87 // get and set signed shorts in the code_array
duke@435 88 inline short short_at(int bci) const { return (short)Bytes::get_Java_u2(&code_array()[bci]); }
duke@435 89 inline void short_at_put(int bci, short value) { Bytes::put_Java_u2((address) &code_array()[bci], value); }
duke@435 90
duke@435 91 // get the address of in the code_array
duke@435 92 inline char* addr_at(int bci) const { return (char*) &code_array()[bci]; }
duke@435 93
duke@435 94 int instruction_length_at(int bci) { return Bytecodes::length_at(code_array() + bci); }
duke@435 95
duke@435 96 // Helper methods
duke@435 97 int align(int n) const { return (n+3) & ~3; }
duke@435 98 int code_slop_pct() const { return 25; }
duke@435 99 bool is_opcode_lookupswitch(Bytecodes::Code bc);
duke@435 100
duke@435 101 // basic relocation methods
duke@435 102 bool relocate_code (int bci, int ilen, int delta);
duke@435 103 void change_jumps (int break_bci, int delta);
duke@435 104 void change_jump (int bci, int offset, bool is_short, int break_bci, int delta);
duke@435 105 void adjust_exception_table(int bci, int delta);
duke@435 106 void adjust_line_no_table (int bci, int delta);
duke@435 107 void adjust_local_var_table(int bci, int delta);
kamg@2232 108 void adjust_stack_map_table(int bci, int delta);
duke@435 109 int get_orig_switch_pad (int bci, bool is_lookup_switch);
duke@435 110 int rc_instr_len (int bci);
duke@435 111 bool expand_code_array (int delta);
duke@435 112
duke@435 113 // Callback support
duke@435 114 RelocatorListener *_listener;
duke@435 115 void notify(int bci, int delta, int new_code_length) {
duke@435 116 if (_listener != NULL)
duke@435 117 _listener->relocated(bci, delta, new_code_length);
duke@435 118 }
duke@435 119 };

mercurial