src/share/vm/runtime/relocator.hpp

Fri, 24 Jun 2016 17:12:13 +0800

author
aoqi<aoqi@loongson.cn>
date
Fri, 24 Jun 2016 17:12:13 +0800
changeset 25
873fd82b133d
parent 1
2d8a650513c2
child 6876
710a3c8b516e
permissions
-rw-r--r--

[Code Reorganization] Removed GC related modifications made by Loongson, for example, UseOldNUMA.

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

mercurial