1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/share/vm/runtime/relocator.hpp Wed Apr 27 01:25:04 2016 +0800 1.3 @@ -0,0 +1,142 @@ 1.4 +/* 1.5 + * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved. 1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.7 + * 1.8 + * This code is free software; you can redistribute it and/or modify it 1.9 + * under the terms of the GNU General Public License version 2 only, as 1.10 + * published by the Free Software Foundation. 1.11 + * 1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1.15 + * version 2 for more details (a copy is included in the LICENSE file that 1.16 + * accompanied this code). 1.17 + * 1.18 + * You should have received a copy of the GNU General Public License version 1.19 + * 2 along with this work; if not, write to the Free Software Foundation, 1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1.21 + * 1.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 1.23 + * or visit www.oracle.com if you need additional information or have any 1.24 + * questions. 1.25 + * 1.26 + */ 1.27 + 1.28 +#ifndef SHARE_VM_RUNTIME_RELOCATOR_HPP 1.29 +#define SHARE_VM_RUNTIME_RELOCATOR_HPP 1.30 + 1.31 +#include "interpreter/bytecodes.hpp" 1.32 +#include "oops/method.hpp" 1.33 +#ifdef TARGET_ARCH_x86 1.34 +# include "bytes_x86.hpp" 1.35 +#endif 1.36 +#ifdef TARGET_ARCH_sparc 1.37 +# include "bytes_sparc.hpp" 1.38 +#endif 1.39 +#ifdef TARGET_ARCH_zero 1.40 +# include "bytes_zero.hpp" 1.41 +#endif 1.42 +#ifdef TARGET_ARCH_arm 1.43 +# include "bytes_arm.hpp" 1.44 +#endif 1.45 +#ifdef TARGET_ARCH_ppc 1.46 +# include "bytes_ppc.hpp" 1.47 +#endif 1.48 + 1.49 +// This code has been converted from the 1.1E java virtual machine 1.50 +// Thanks to the JavaTopics group for using the code 1.51 + 1.52 +class ChangeItem; 1.53 + 1.54 +// Callback object for code relocations 1.55 +class RelocatorListener : public StackObj { 1.56 + public: 1.57 + RelocatorListener() {}; 1.58 + virtual void relocated(int bci, int delta, int new_method_size) = 0; 1.59 +}; 1.60 + 1.61 + 1.62 +class Relocator : public ResourceObj { 1.63 + public: 1.64 + Relocator(methodHandle method, RelocatorListener* listener); 1.65 + methodHandle insert_space_at(int bci, int space, u_char inst_buffer[], TRAPS); 1.66 + 1.67 + // Callbacks from ChangeItem's 1.68 + bool handle_code_changes(); 1.69 + bool handle_widen (int bci, int new_ilen, u_char inst_buffer[]); // handles general instructions 1.70 + void push_jump_widen (int bci, int delta, int new_delta); // pushes jumps 1.71 + bool handle_jump_widen (int bci, int delta); // handles jumps 1.72 + bool handle_switch_pad (int bci, int old_pad, bool is_lookup_switch); // handles table and lookup switches 1.73 + 1.74 + private: 1.75 + unsigned char* _code_array; 1.76 + int _code_array_length; 1.77 + int _code_length; 1.78 + unsigned char* _compressed_line_number_table; 1.79 + int _compressed_line_number_table_size; 1.80 + methodHandle _method; 1.81 + u_char _overwrite[3]; // stores overwritten bytes for shrunken instructions 1.82 + 1.83 + GrowableArray<ChangeItem*>* _changes; 1.84 + 1.85 + unsigned char* code_array() const { return _code_array; } 1.86 + void set_code_array(unsigned char* array) { _code_array = array; } 1.87 + 1.88 + int code_length() const { return _code_length; } 1.89 + void set_code_length(int length) { _code_length = length; } 1.90 + 1.91 + int code_array_length() const { return _code_array_length; } 1.92 + void set_code_array_length(int length) { _code_array_length = length; } 1.93 + 1.94 + unsigned char* compressed_line_number_table() const { return _compressed_line_number_table; } 1.95 + void set_compressed_line_number_table(unsigned char* table) { _compressed_line_number_table = table; } 1.96 + 1.97 + int compressed_line_number_table_size() const { return _compressed_line_number_table_size; } 1.98 + void set_compressed_line_number_table_size(int size) { _compressed_line_number_table_size = size; } 1.99 + 1.100 + methodHandle method() const { return _method; } 1.101 + void set_method(methodHandle method) { _method = method; } 1.102 + 1.103 + // This will return a raw bytecode, which is possibly rewritten. 1.104 + Bytecodes::Code code_at(int bci) const { return (Bytecodes::Code) code_array()[bci]; } 1.105 + void code_at_put(int bci, Bytecodes::Code code) { code_array()[bci] = (char) code; } 1.106 + 1.107 + // get and set signed integers in the code_array 1.108 + inline int int_at(int bci) const { return Bytes::get_Java_u4(&code_array()[bci]); } 1.109 + inline void int_at_put(int bci, int value) { Bytes::put_Java_u4(&code_array()[bci], value); } 1.110 + 1.111 + // get and set signed shorts in the code_array 1.112 + inline short short_at(int bci) const { return (short)Bytes::get_Java_u2(&code_array()[bci]); } 1.113 + inline void short_at_put(int bci, short value) { Bytes::put_Java_u2((address) &code_array()[bci], value); } 1.114 + 1.115 + // get the address of in the code_array 1.116 + inline char* addr_at(int bci) const { return (char*) &code_array()[bci]; } 1.117 + 1.118 + int instruction_length_at(int bci) { return Bytecodes::length_at(NULL, code_array() + bci); } 1.119 + 1.120 + // Helper methods 1.121 + int align(int n) const { return (n+3) & ~3; } 1.122 + int code_slop_pct() const { return 25; } 1.123 + bool is_opcode_lookupswitch(Bytecodes::Code bc); 1.124 + 1.125 + // basic relocation methods 1.126 + bool relocate_code (int bci, int ilen, int delta); 1.127 + void change_jumps (int break_bci, int delta); 1.128 + void change_jump (int bci, int offset, bool is_short, int break_bci, int delta); 1.129 + void adjust_exception_table(int bci, int delta); 1.130 + void adjust_line_no_table (int bci, int delta); 1.131 + void adjust_local_var_table(int bci, int delta); 1.132 + void adjust_stack_map_table(int bci, int delta); 1.133 + int get_orig_switch_pad (int bci, bool is_lookup_switch); 1.134 + int rc_instr_len (int bci); 1.135 + bool expand_code_array (int delta); 1.136 + 1.137 + // Callback support 1.138 + RelocatorListener *_listener; 1.139 + void notify(int bci, int delta, int new_code_length) { 1.140 + if (_listener != NULL) 1.141 + _listener->relocated(bci, delta, new_code_length); 1.142 + } 1.143 +}; 1.144 + 1.145 +#endif // SHARE_VM_RUNTIME_RELOCATOR_HPP