src/share/vm/runtime/relocator.hpp

Wed, 31 Jan 2018 19:24:57 -0500

author
dbuck
date
Wed, 31 Jan 2018 19:24:57 -0500
changeset 9289
427b2fb1944f
parent 4037
da91efe96a93
child 6876
710a3c8b516e
permissions
-rw-r--r--

8189170: Add option to disable stack overflow checking in primordial thread for use with JNI_CreateJavaJVM
Reviewed-by: dcubed

duke@435 1 /*
coleenp@4037 2 * Copyright (c) 1997, 2012, 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
stefank@2314 25 #ifndef SHARE_VM_RUNTIME_RELOCATOR_HPP
stefank@2314 26 #define SHARE_VM_RUNTIME_RELOCATOR_HPP
stefank@2314 27
stefank@2314 28 #include "interpreter/bytecodes.hpp"
coleenp@4037 29 #include "oops/method.hpp"
stefank@2314 30 #ifdef TARGET_ARCH_x86
stefank@2314 31 # include "bytes_x86.hpp"
stefank@2314 32 #endif
stefank@2314 33 #ifdef TARGET_ARCH_sparc
stefank@2314 34 # include "bytes_sparc.hpp"
stefank@2314 35 #endif
stefank@2314 36 #ifdef TARGET_ARCH_zero
stefank@2314 37 # include "bytes_zero.hpp"
stefank@2314 38 #endif
bobv@2508 39 #ifdef TARGET_ARCH_arm
bobv@2508 40 # include "bytes_arm.hpp"
bobv@2508 41 #endif
bobv@2508 42 #ifdef TARGET_ARCH_ppc
bobv@2508 43 # include "bytes_ppc.hpp"
bobv@2508 44 #endif
stefank@2314 45
duke@435 46 // This code has been converted from the 1.1E java virtual machine
duke@435 47 // Thanks to the JavaTopics group for using the code
duke@435 48
duke@435 49 class ChangeItem;
duke@435 50
duke@435 51 // Callback object for code relocations
duke@435 52 class RelocatorListener : public StackObj {
duke@435 53 public:
duke@435 54 RelocatorListener() {};
duke@435 55 virtual void relocated(int bci, int delta, int new_method_size) = 0;
duke@435 56 };
duke@435 57
duke@435 58
duke@435 59 class Relocator : public ResourceObj {
duke@435 60 public:
duke@435 61 Relocator(methodHandle method, RelocatorListener* listener);
duke@435 62 methodHandle insert_space_at(int bci, int space, u_char inst_buffer[], TRAPS);
duke@435 63
duke@435 64 // Callbacks from ChangeItem's
duke@435 65 bool handle_code_changes();
duke@435 66 bool handle_widen (int bci, int new_ilen, u_char inst_buffer[]); // handles general instructions
duke@435 67 void push_jump_widen (int bci, int delta, int new_delta); // pushes jumps
duke@435 68 bool handle_jump_widen (int bci, int delta); // handles jumps
duke@435 69 bool handle_switch_pad (int bci, int old_pad, bool is_lookup_switch); // handles table and lookup switches
duke@435 70
duke@435 71 private:
duke@435 72 unsigned char* _code_array;
duke@435 73 int _code_array_length;
duke@435 74 int _code_length;
duke@435 75 unsigned char* _compressed_line_number_table;
duke@435 76 int _compressed_line_number_table_size;
duke@435 77 methodHandle _method;
duke@435 78 u_char _overwrite[3]; // stores overwritten bytes for shrunken instructions
duke@435 79
duke@435 80 GrowableArray<ChangeItem*>* _changes;
duke@435 81
duke@435 82 unsigned char* code_array() const { return _code_array; }
duke@435 83 void set_code_array(unsigned char* array) { _code_array = array; }
duke@435 84
duke@435 85 int code_length() const { return _code_length; }
duke@435 86 void set_code_length(int length) { _code_length = length; }
duke@435 87
duke@435 88 int code_array_length() const { return _code_array_length; }
duke@435 89 void set_code_array_length(int length) { _code_array_length = length; }
duke@435 90
duke@435 91 unsigned char* compressed_line_number_table() const { return _compressed_line_number_table; }
duke@435 92 void set_compressed_line_number_table(unsigned char* table) { _compressed_line_number_table = table; }
duke@435 93
duke@435 94 int compressed_line_number_table_size() const { return _compressed_line_number_table_size; }
duke@435 95 void set_compressed_line_number_table_size(int size) { _compressed_line_number_table_size = size; }
duke@435 96
duke@435 97 methodHandle method() const { return _method; }
duke@435 98 void set_method(methodHandle method) { _method = method; }
duke@435 99
duke@435 100 // This will return a raw bytecode, which is possibly rewritten.
duke@435 101 Bytecodes::Code code_at(int bci) const { return (Bytecodes::Code) code_array()[bci]; }
duke@435 102 void code_at_put(int bci, Bytecodes::Code code) { code_array()[bci] = (char) code; }
duke@435 103
duke@435 104 // get and set signed integers in the code_array
duke@435 105 inline int int_at(int bci) const { return Bytes::get_Java_u4(&code_array()[bci]); }
duke@435 106 inline void int_at_put(int bci, int value) { Bytes::put_Java_u4(&code_array()[bci], value); }
duke@435 107
duke@435 108 // get and set signed shorts in the code_array
duke@435 109 inline short short_at(int bci) const { return (short)Bytes::get_Java_u2(&code_array()[bci]); }
duke@435 110 inline void short_at_put(int bci, short value) { Bytes::put_Java_u2((address) &code_array()[bci], value); }
duke@435 111
duke@435 112 // get the address of in the code_array
duke@435 113 inline char* addr_at(int bci) const { return (char*) &code_array()[bci]; }
duke@435 114
never@2466 115 int instruction_length_at(int bci) { return Bytecodes::length_at(NULL, code_array() + bci); }
duke@435 116
duke@435 117 // Helper methods
duke@435 118 int align(int n) const { return (n+3) & ~3; }
duke@435 119 int code_slop_pct() const { return 25; }
duke@435 120 bool is_opcode_lookupswitch(Bytecodes::Code bc);
duke@435 121
duke@435 122 // basic relocation methods
duke@435 123 bool relocate_code (int bci, int ilen, int delta);
duke@435 124 void change_jumps (int break_bci, int delta);
duke@435 125 void change_jump (int bci, int offset, bool is_short, int break_bci, int delta);
duke@435 126 void adjust_exception_table(int bci, int delta);
duke@435 127 void adjust_line_no_table (int bci, int delta);
duke@435 128 void adjust_local_var_table(int bci, int delta);
kamg@2232 129 void adjust_stack_map_table(int bci, int delta);
duke@435 130 int get_orig_switch_pad (int bci, bool is_lookup_switch);
duke@435 131 int rc_instr_len (int bci);
duke@435 132 bool expand_code_array (int delta);
duke@435 133
duke@435 134 // Callback support
duke@435 135 RelocatorListener *_listener;
duke@435 136 void notify(int bci, int delta, int new_code_length) {
duke@435 137 if (_listener != NULL)
duke@435 138 _listener->relocated(bci, delta, new_code_length);
duke@435 139 }
duke@435 140 };
stefank@2314 141
stefank@2314 142 #endif // SHARE_VM_RUNTIME_RELOCATOR_HPP

mercurial