annotate src/share/vm/runtime/relocator.hpp @ 18096:ca6d25be853b jdk8u25-b13

8044269: Analysis of archive files. Summary: Add checksum verification. Reviewed-by: iklam, dholmes, mschoene
author jiangli
date Tue, 12 Aug 2014 17:46:16 -0400
parents da91efe96a93
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1 /*
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 2192
diff changeset
2 * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
0
a61af66fc99e Initial load
duke
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
a61af66fc99e Initial load
duke
parents:
diff changeset
4 *
a61af66fc99e Initial load
duke
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
a61af66fc99e Initial load
duke
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
a61af66fc99e Initial load
duke
parents:
diff changeset
7 * published by the Free Software Foundation.
a61af66fc99e Initial load
duke
parents:
diff changeset
8 *
a61af66fc99e Initial load
duke
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
a61af66fc99e Initial load
duke
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
a61af66fc99e Initial load
duke
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
a61af66fc99e Initial load
duke
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
a61af66fc99e Initial load
duke
parents:
diff changeset
13 * accompanied this code).
a61af66fc99e Initial load
duke
parents:
diff changeset
14 *
a61af66fc99e Initial load
duke
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
a61af66fc99e Initial load
duke
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
a61af66fc99e Initial load
duke
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
a61af66fc99e Initial load
duke
parents:
diff changeset
18 *
1552
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 0
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 0
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 0
diff changeset
21 * questions.
0
a61af66fc99e Initial load
duke
parents:
diff changeset
22 *
a61af66fc99e Initial load
duke
parents:
diff changeset
23 */
a61af66fc99e Initial load
duke
parents:
diff changeset
24
1972
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1877
diff changeset
25 #ifndef SHARE_VM_RUNTIME_RELOCATOR_HPP
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1877
diff changeset
26 #define SHARE_VM_RUNTIME_RELOCATOR_HPP
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1877
diff changeset
27
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1877
diff changeset
28 #include "interpreter/bytecodes.hpp"
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 2192
diff changeset
29 #include "oops/method.hpp"
1972
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1877
diff changeset
30 #ifdef TARGET_ARCH_x86
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1877
diff changeset
31 # include "bytes_x86.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1877
diff changeset
32 #endif
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1877
diff changeset
33 #ifdef TARGET_ARCH_sparc
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1877
diff changeset
34 # include "bytes_sparc.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1877
diff changeset
35 #endif
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1877
diff changeset
36 #ifdef TARGET_ARCH_zero
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1877
diff changeset
37 # include "bytes_zero.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1877
diff changeset
38 #endif
2192
b92c45f2bc75 7016023: Enable building ARM and PPC from src/closed repository
bobv
parents: 2146
diff changeset
39 #ifdef TARGET_ARCH_arm
b92c45f2bc75 7016023: Enable building ARM and PPC from src/closed repository
bobv
parents: 2146
diff changeset
40 # include "bytes_arm.hpp"
b92c45f2bc75 7016023: Enable building ARM and PPC from src/closed repository
bobv
parents: 2146
diff changeset
41 #endif
b92c45f2bc75 7016023: Enable building ARM and PPC from src/closed repository
bobv
parents: 2146
diff changeset
42 #ifdef TARGET_ARCH_ppc
b92c45f2bc75 7016023: Enable building ARM and PPC from src/closed repository
bobv
parents: 2146
diff changeset
43 # include "bytes_ppc.hpp"
b92c45f2bc75 7016023: Enable building ARM and PPC from src/closed repository
bobv
parents: 2146
diff changeset
44 #endif
1972
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1877
diff changeset
45
0
a61af66fc99e Initial load
duke
parents:
diff changeset
46 // This code has been converted from the 1.1E java virtual machine
a61af66fc99e Initial load
duke
parents:
diff changeset
47 // Thanks to the JavaTopics group for using the code
a61af66fc99e Initial load
duke
parents:
diff changeset
48
a61af66fc99e Initial load
duke
parents:
diff changeset
49 class ChangeItem;
a61af66fc99e Initial load
duke
parents:
diff changeset
50
a61af66fc99e Initial load
duke
parents:
diff changeset
51 // Callback object for code relocations
a61af66fc99e Initial load
duke
parents:
diff changeset
52 class RelocatorListener : public StackObj {
a61af66fc99e Initial load
duke
parents:
diff changeset
53 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
54 RelocatorListener() {};
a61af66fc99e Initial load
duke
parents:
diff changeset
55 virtual void relocated(int bci, int delta, int new_method_size) = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
56 };
a61af66fc99e Initial load
duke
parents:
diff changeset
57
a61af66fc99e Initial load
duke
parents:
diff changeset
58
a61af66fc99e Initial load
duke
parents:
diff changeset
59 class Relocator : public ResourceObj {
a61af66fc99e Initial load
duke
parents:
diff changeset
60 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
61 Relocator(methodHandle method, RelocatorListener* listener);
a61af66fc99e Initial load
duke
parents:
diff changeset
62 methodHandle insert_space_at(int bci, int space, u_char inst_buffer[], TRAPS);
a61af66fc99e Initial load
duke
parents:
diff changeset
63
a61af66fc99e Initial load
duke
parents:
diff changeset
64 // Callbacks from ChangeItem's
a61af66fc99e Initial load
duke
parents:
diff changeset
65 bool handle_code_changes();
a61af66fc99e Initial load
duke
parents:
diff changeset
66 bool handle_widen (int bci, int new_ilen, u_char inst_buffer[]); // handles general instructions
a61af66fc99e Initial load
duke
parents:
diff changeset
67 void push_jump_widen (int bci, int delta, int new_delta); // pushes jumps
a61af66fc99e Initial load
duke
parents:
diff changeset
68 bool handle_jump_widen (int bci, int delta); // handles jumps
a61af66fc99e Initial load
duke
parents:
diff changeset
69 bool handle_switch_pad (int bci, int old_pad, bool is_lookup_switch); // handles table and lookup switches
a61af66fc99e Initial load
duke
parents:
diff changeset
70
a61af66fc99e Initial load
duke
parents:
diff changeset
71 private:
a61af66fc99e Initial load
duke
parents:
diff changeset
72 unsigned char* _code_array;
a61af66fc99e Initial load
duke
parents:
diff changeset
73 int _code_array_length;
a61af66fc99e Initial load
duke
parents:
diff changeset
74 int _code_length;
a61af66fc99e Initial load
duke
parents:
diff changeset
75 unsigned char* _compressed_line_number_table;
a61af66fc99e Initial load
duke
parents:
diff changeset
76 int _compressed_line_number_table_size;
a61af66fc99e Initial load
duke
parents:
diff changeset
77 methodHandle _method;
a61af66fc99e Initial load
duke
parents:
diff changeset
78 u_char _overwrite[3]; // stores overwritten bytes for shrunken instructions
a61af66fc99e Initial load
duke
parents:
diff changeset
79
a61af66fc99e Initial load
duke
parents:
diff changeset
80 GrowableArray<ChangeItem*>* _changes;
a61af66fc99e Initial load
duke
parents:
diff changeset
81
a61af66fc99e Initial load
duke
parents:
diff changeset
82 unsigned char* code_array() const { return _code_array; }
a61af66fc99e Initial load
duke
parents:
diff changeset
83 void set_code_array(unsigned char* array) { _code_array = array; }
a61af66fc99e Initial load
duke
parents:
diff changeset
84
a61af66fc99e Initial load
duke
parents:
diff changeset
85 int code_length() const { return _code_length; }
a61af66fc99e Initial load
duke
parents:
diff changeset
86 void set_code_length(int length) { _code_length = length; }
a61af66fc99e Initial load
duke
parents:
diff changeset
87
a61af66fc99e Initial load
duke
parents:
diff changeset
88 int code_array_length() const { return _code_array_length; }
a61af66fc99e Initial load
duke
parents:
diff changeset
89 void set_code_array_length(int length) { _code_array_length = length; }
a61af66fc99e Initial load
duke
parents:
diff changeset
90
a61af66fc99e Initial load
duke
parents:
diff changeset
91 unsigned char* compressed_line_number_table() const { return _compressed_line_number_table; }
a61af66fc99e Initial load
duke
parents:
diff changeset
92 void set_compressed_line_number_table(unsigned char* table) { _compressed_line_number_table = table; }
a61af66fc99e Initial load
duke
parents:
diff changeset
93
a61af66fc99e Initial load
duke
parents:
diff changeset
94 int compressed_line_number_table_size() const { return _compressed_line_number_table_size; }
a61af66fc99e Initial load
duke
parents:
diff changeset
95 void set_compressed_line_number_table_size(int size) { _compressed_line_number_table_size = size; }
a61af66fc99e Initial load
duke
parents:
diff changeset
96
a61af66fc99e Initial load
duke
parents:
diff changeset
97 methodHandle method() const { return _method; }
a61af66fc99e Initial load
duke
parents:
diff changeset
98 void set_method(methodHandle method) { _method = method; }
a61af66fc99e Initial load
duke
parents:
diff changeset
99
a61af66fc99e Initial load
duke
parents:
diff changeset
100 // This will return a raw bytecode, which is possibly rewritten.
a61af66fc99e Initial load
duke
parents:
diff changeset
101 Bytecodes::Code code_at(int bci) const { return (Bytecodes::Code) code_array()[bci]; }
a61af66fc99e Initial load
duke
parents:
diff changeset
102 void code_at_put(int bci, Bytecodes::Code code) { code_array()[bci] = (char) code; }
a61af66fc99e Initial load
duke
parents:
diff changeset
103
a61af66fc99e Initial load
duke
parents:
diff changeset
104 // get and set signed integers in the code_array
a61af66fc99e Initial load
duke
parents:
diff changeset
105 inline int int_at(int bci) const { return Bytes::get_Java_u4(&code_array()[bci]); }
a61af66fc99e Initial load
duke
parents:
diff changeset
106 inline void int_at_put(int bci, int value) { Bytes::put_Java_u4(&code_array()[bci], value); }
a61af66fc99e Initial load
duke
parents:
diff changeset
107
a61af66fc99e Initial load
duke
parents:
diff changeset
108 // get and set signed shorts in the code_array
a61af66fc99e Initial load
duke
parents:
diff changeset
109 inline short short_at(int bci) const { return (short)Bytes::get_Java_u2(&code_array()[bci]); }
a61af66fc99e Initial load
duke
parents:
diff changeset
110 inline void short_at_put(int bci, short value) { Bytes::put_Java_u2((address) &code_array()[bci], value); }
a61af66fc99e Initial load
duke
parents:
diff changeset
111
a61af66fc99e Initial load
duke
parents:
diff changeset
112 // get the address of in the code_array
a61af66fc99e Initial load
duke
parents:
diff changeset
113 inline char* addr_at(int bci) const { return (char*) &code_array()[bci]; }
a61af66fc99e Initial load
duke
parents:
diff changeset
114
2146
2f33b03bd915 7013008: 2/3 assert(method == NULL || check_method(method, bcp)) failed: bcp must point into method
never
parents: 2142
diff changeset
115 int instruction_length_at(int bci) { return Bytecodes::length_at(NULL, code_array() + bci); }
0
a61af66fc99e Initial load
duke
parents:
diff changeset
116
a61af66fc99e Initial load
duke
parents:
diff changeset
117 // Helper methods
a61af66fc99e Initial load
duke
parents:
diff changeset
118 int align(int n) const { return (n+3) & ~3; }
a61af66fc99e Initial load
duke
parents:
diff changeset
119 int code_slop_pct() const { return 25; }
a61af66fc99e Initial load
duke
parents:
diff changeset
120 bool is_opcode_lookupswitch(Bytecodes::Code bc);
a61af66fc99e Initial load
duke
parents:
diff changeset
121
a61af66fc99e Initial load
duke
parents:
diff changeset
122 // basic relocation methods
a61af66fc99e Initial load
duke
parents:
diff changeset
123 bool relocate_code (int bci, int ilen, int delta);
a61af66fc99e Initial load
duke
parents:
diff changeset
124 void change_jumps (int break_bci, int delta);
a61af66fc99e Initial load
duke
parents:
diff changeset
125 void change_jump (int bci, int offset, bool is_short, int break_bci, int delta);
a61af66fc99e Initial load
duke
parents:
diff changeset
126 void adjust_exception_table(int bci, int delta);
a61af66fc99e Initial load
duke
parents:
diff changeset
127 void adjust_line_no_table (int bci, int delta);
a61af66fc99e Initial load
duke
parents:
diff changeset
128 void adjust_local_var_table(int bci, int delta);
1877
a4c7fe54bf3f 6991315: RedefineClasses fails with java.lang.VerifyError
kamg
parents: 1552
diff changeset
129 void adjust_stack_map_table(int bci, int delta);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
130 int get_orig_switch_pad (int bci, bool is_lookup_switch);
a61af66fc99e Initial load
duke
parents:
diff changeset
131 int rc_instr_len (int bci);
a61af66fc99e Initial load
duke
parents:
diff changeset
132 bool expand_code_array (int delta);
a61af66fc99e Initial load
duke
parents:
diff changeset
133
a61af66fc99e Initial load
duke
parents:
diff changeset
134 // Callback support
a61af66fc99e Initial load
duke
parents:
diff changeset
135 RelocatorListener *_listener;
a61af66fc99e Initial load
duke
parents:
diff changeset
136 void notify(int bci, int delta, int new_code_length) {
a61af66fc99e Initial load
duke
parents:
diff changeset
137 if (_listener != NULL)
a61af66fc99e Initial load
duke
parents:
diff changeset
138 _listener->relocated(bci, delta, new_code_length);
a61af66fc99e Initial load
duke
parents:
diff changeset
139 }
a61af66fc99e Initial load
duke
parents:
diff changeset
140 };
1972
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1877
diff changeset
141
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1877
diff changeset
142 #endif // SHARE_VM_RUNTIME_RELOCATOR_HPP