author | erikj |
Tue, 12 Sep 2017 19:03:39 +0200 | |
changeset 47216 | 71c04702a3d5 |
parent 33593 | hotspot/src/share/vm/runtime/relocator.hpp@60764a78fa5c |
child 53244 | 9807daeb47c4 |
permissions | -rw-r--r-- |
1 | 1 |
/* |
33593
60764a78fa5c
8140274: methodHandles and constantPoolHandles should be passed as const references
coleenp
parents:
25715
diff
changeset
|
2 |
* Copyright (c) 1997, 2015, Oracle and/or its affiliates. All rights reserved. |
1 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. |
|
8 |
* |
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
13 |
* accompanied this code). |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License version |
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
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 | 22 |
* |
23 |
*/ |
|
24 |
||
7397 | 25 |
#ifndef SHARE_VM_RUNTIME_RELOCATOR_HPP |
26 |
#define SHARE_VM_RUNTIME_RELOCATOR_HPP |
|
27 |
||
28 |
#include "interpreter/bytecodes.hpp" |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
8107
diff
changeset
|
29 |
#include "oops/method.hpp" |
25715
d5a8dbdc5150
8049325: Introduce and clean up umbrella headers for the files in the cpu subdirectories.
goetz
parents:
13728
diff
changeset
|
30 |
#include "utilities/bytes.hpp" |
7397 | 31 |
|
1 | 32 |
// This code has been converted from the 1.1E java virtual machine |
33 |
// Thanks to the JavaTopics group for using the code |
|
34 |
||
35 |
class ChangeItem; |
|
36 |
||
37 |
// Callback object for code relocations |
|
38 |
class RelocatorListener : public StackObj { |
|
39 |
public: |
|
40 |
RelocatorListener() {}; |
|
41 |
virtual void relocated(int bci, int delta, int new_method_size) = 0; |
|
42 |
}; |
|
43 |
||
44 |
||
45 |
class Relocator : public ResourceObj { |
|
46 |
public: |
|
33593
60764a78fa5c
8140274: methodHandles and constantPoolHandles should be passed as const references
coleenp
parents:
25715
diff
changeset
|
47 |
Relocator(const methodHandle& method, RelocatorListener* listener); |
1 | 48 |
methodHandle insert_space_at(int bci, int space, u_char inst_buffer[], TRAPS); |
49 |
||
50 |
// Callbacks from ChangeItem's |
|
51 |
bool handle_code_changes(); |
|
52 |
bool handle_widen (int bci, int new_ilen, u_char inst_buffer[]); // handles general instructions |
|
53 |
void push_jump_widen (int bci, int delta, int new_delta); // pushes jumps |
|
54 |
bool handle_jump_widen (int bci, int delta); // handles jumps |
|
55 |
bool handle_switch_pad (int bci, int old_pad, bool is_lookup_switch); // handles table and lookup switches |
|
56 |
||
57 |
private: |
|
58 |
unsigned char* _code_array; |
|
59 |
int _code_array_length; |
|
60 |
int _code_length; |
|
61 |
unsigned char* _compressed_line_number_table; |
|
62 |
int _compressed_line_number_table_size; |
|
63 |
methodHandle _method; |
|
64 |
u_char _overwrite[3]; // stores overwritten bytes for shrunken instructions |
|
65 |
||
66 |
GrowableArray<ChangeItem*>* _changes; |
|
67 |
||
68 |
unsigned char* code_array() const { return _code_array; } |
|
69 |
void set_code_array(unsigned char* array) { _code_array = array; } |
|
70 |
||
71 |
int code_length() const { return _code_length; } |
|
72 |
void set_code_length(int length) { _code_length = length; } |
|
73 |
||
74 |
int code_array_length() const { return _code_array_length; } |
|
75 |
void set_code_array_length(int length) { _code_array_length = length; } |
|
76 |
||
77 |
unsigned char* compressed_line_number_table() const { return _compressed_line_number_table; } |
|
78 |
void set_compressed_line_number_table(unsigned char* table) { _compressed_line_number_table = table; } |
|
79 |
||
80 |
int compressed_line_number_table_size() const { return _compressed_line_number_table_size; } |
|
81 |
void set_compressed_line_number_table_size(int size) { _compressed_line_number_table_size = size; } |
|
82 |
||
83 |
methodHandle method() const { return _method; } |
|
33593
60764a78fa5c
8140274: methodHandles and constantPoolHandles should be passed as const references
coleenp
parents:
25715
diff
changeset
|
84 |
void set_method(const methodHandle& method) { _method = method; } |
1 | 85 |
|
86 |
// This will return a raw bytecode, which is possibly rewritten. |
|
87 |
Bytecodes::Code code_at(int bci) const { return (Bytecodes::Code) code_array()[bci]; } |
|
88 |
void code_at_put(int bci, Bytecodes::Code code) { code_array()[bci] = (char) code; } |
|
89 |
||
90 |
// get and set signed integers in the code_array |
|
91 |
inline int int_at(int bci) const { return Bytes::get_Java_u4(&code_array()[bci]); } |
|
92 |
inline void int_at_put(int bci, int value) { Bytes::put_Java_u4(&code_array()[bci], value); } |
|
93 |
||
94 |
// get and set signed shorts in the code_array |
|
95 |
inline short short_at(int bci) const { return (short)Bytes::get_Java_u2(&code_array()[bci]); } |
|
96 |
inline void short_at_put(int bci, short value) { Bytes::put_Java_u2((address) &code_array()[bci], value); } |
|
97 |
||
98 |
// get the address of in the code_array |
|
99 |
inline char* addr_at(int bci) const { return (char*) &code_array()[bci]; } |
|
100 |
||
7917
5c35c053175b
7013008: 2/3 assert(method == NULL || check_method(method, bcp)) failed: bcp must point into method
never
parents:
7913
diff
changeset
|
101 |
int instruction_length_at(int bci) { return Bytecodes::length_at(NULL, code_array() + bci); } |
1 | 102 |
|
103 |
// Helper methods |
|
104 |
int align(int n) const { return (n+3) & ~3; } |
|
105 |
int code_slop_pct() const { return 25; } |
|
106 |
bool is_opcode_lookupswitch(Bytecodes::Code bc); |
|
107 |
||
108 |
// basic relocation methods |
|
109 |
bool relocate_code (int bci, int ilen, int delta); |
|
110 |
void change_jumps (int break_bci, int delta); |
|
111 |
void change_jump (int bci, int offset, bool is_short, int break_bci, int delta); |
|
112 |
void adjust_exception_table(int bci, int delta); |
|
113 |
void adjust_line_no_table (int bci, int delta); |
|
114 |
void adjust_local_var_table(int bci, int delta); |
|
6974
a013f1c533a5
6991315: RedefineClasses fails with java.lang.VerifyError
kamg
parents:
5547
diff
changeset
|
115 |
void adjust_stack_map_table(int bci, int delta); |
1 | 116 |
int get_orig_switch_pad (int bci, bool is_lookup_switch); |
117 |
int rc_instr_len (int bci); |
|
118 |
bool expand_code_array (int delta); |
|
119 |
||
120 |
// Callback support |
|
121 |
RelocatorListener *_listener; |
|
122 |
void notify(int bci, int delta, int new_code_length) { |
|
123 |
if (_listener != NULL) |
|
124 |
_listener->relocated(bci, delta, new_code_length); |
|
125 |
} |
|
126 |
}; |
|
7397 | 127 |
|
128 |
#endif // SHARE_VM_RUNTIME_RELOCATOR_HPP |