author | lfoltan |
Mon, 21 Oct 2019 13:13:16 -0400 | |
changeset 58722 | cba8afa5cfed |
parent 53244 | 9807daeb47c4 |
permissions | -rw-r--r-- |
1 | 1 |
/* |
53244
9807daeb47c4
8216167: Update include guards to reflect correct directories
coleenp
parents:
49449
diff
changeset
|
2 |
* Copyright (c) 2003, 2019, 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 |
||
53244
9807daeb47c4
8216167: Update include guards to reflect correct directories
coleenp
parents:
49449
diff
changeset
|
25 |
#ifndef SHARE_CLASSFILE_STACKMAPTABLE_HPP |
9807daeb47c4
8216167: Update include guards to reflect correct directories
coleenp
parents:
49449
diff
changeset
|
26 |
#define SHARE_CLASSFILE_STACKMAPTABLE_HPP |
7397 | 27 |
|
28 |
#include "classfile/stackMapFrame.hpp" |
|
13476 | 29 |
#include "classfile/verifier.hpp" |
7397 | 30 |
#include "memory/allocation.hpp" |
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13476
diff
changeset
|
31 |
#include "oops/constantPool.hpp" |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13476
diff
changeset
|
32 |
#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
|
33 |
#include "utilities/bytes.hpp" |
7397 | 34 |
#include "utilities/globalDefinitions.hpp" |
35 |
||
1 | 36 |
class StackMapReader; |
37 |
||
38 |
// StackMapTable class is the StackMap table used by type checker |
|
39 |
class StackMapTable : public StackObj { |
|
40 |
private: |
|
41 |
// Logically, the _frame_count (as well as many fields in the StackFrame) |
|
42 |
// should be a u2, but if we defined the variable as that type it will |
|
43 |
// be difficult to detect/recover from overflow or underflow conditions. |
|
44 |
// Widening the type and making it signed will help detect these. |
|
45 |
int32_t _code_length; |
|
46 |
int32_t _frame_count; // Stackmap frame count |
|
47 |
StackMapFrame** _frame_array; |
|
48 |
||
49 |
public: |
|
50 |
StackMapTable(StackMapReader* reader, StackMapFrame* init_frame, |
|
51 |
u2 max_locals, u2 max_stack, |
|
52 |
char* code_data, int code_len, TRAPS); |
|
53 |
||
54 |
inline int32_t get_frame_count() const { return _frame_count; } |
|
55 |
inline int get_offset(int index) const { |
|
56 |
return _frame_array[index]->offset(); |
|
57 |
} |
|
58 |
||
59 |
// Match and/or update current_frame to the frame in stackmap table with |
|
60 |
// specified offset. Return true if the two frames match. |
|
61 |
bool match_stackmap( |
|
62 |
StackMapFrame* current_frame, int32_t offset, |
|
43179
06ccf3bfd0a3
8167104: Additional class construction refinements
hseigel
parents:
25900
diff
changeset
|
63 |
bool match, bool update, ErrorContext* ctx, TRAPS) const; |
1 | 64 |
// Match and/or update current_frame to the frame in stackmap table with |
65 |
// specified offset and frame index. Return true if the two frames match. |
|
66 |
bool match_stackmap( |
|
67 |
StackMapFrame* current_frame, int32_t offset, int32_t frame_index, |
|
43179
06ccf3bfd0a3
8167104: Additional class construction refinements
hseigel
parents:
25900
diff
changeset
|
68 |
bool match, bool update, ErrorContext* ctx, TRAPS) const; |
1 | 69 |
|
70 |
// Check jump instructions. Make sure there are no uninitialized |
|
71 |
// instances on backward branch. |
|
72 |
void check_jump_target(StackMapFrame* frame, int32_t target, TRAPS) const; |
|
73 |
||
74 |
// The following methods are only used inside this class. |
|
75 |
||
76 |
// Returns the frame array index where the frame with offset is stored. |
|
77 |
int get_index_from_offset(int32_t offset) const; |
|
78 |
||
13476 | 79 |
void print_on(outputStream* str) const; |
1 | 80 |
}; |
81 |
||
82 |
class StackMapStream : StackObj { |
|
83 |
private: |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13476
diff
changeset
|
84 |
Array<u1>* _data; |
1 | 85 |
int _index; |
86 |
public: |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13476
diff
changeset
|
87 |
StackMapStream(Array<u1>* ah) |
1 | 88 |
: _data(ah), _index(0) { |
89 |
} |
|
90 |
u1 get_u1(TRAPS) { |
|
91 |
if (_data == NULL || _index >= _data->length()) { |
|
92 |
stackmap_format_error("access beyond the end of attribute", CHECK_0); |
|
93 |
} |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13476
diff
changeset
|
94 |
return _data->at(_index++); |
1 | 95 |
} |
96 |
u2 get_u2(TRAPS) { |
|
97 |
if (_data == NULL || _index >= _data->length() - 1) { |
|
98 |
stackmap_format_error("access beyond the end of attribute", CHECK_0); |
|
99 |
} |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13476
diff
changeset
|
100 |
u2 res = Bytes::get_Java_u2(_data->adr_at(_index)); |
1 | 101 |
_index += 2; |
102 |
return res; |
|
103 |
} |
|
104 |
bool at_end() { |
|
105 |
return (_data == NULL) || (_index == _data->length()); |
|
106 |
} |
|
107 |
static void stackmap_format_error(const char* msg, TRAPS); |
|
108 |
}; |
|
109 |
||
110 |
class StackMapReader : StackObj { |
|
111 |
private: |
|
112 |
// information about the class and method |
|
113 |
constantPoolHandle _cp; |
|
114 |
ClassVerifier* _verifier; |
|
115 |
StackMapStream* _stream; |
|
116 |
char* _code_data; |
|
117 |
int32_t _code_length; |
|
118 |
||
119 |
// information get from the attribute |
|
120 |
int32_t _frame_count; // frame count |
|
121 |
||
122 |
int32_t chop(VerificationType* locals, int32_t length, int32_t chops); |
|
123 |
VerificationType parse_verification_type(u1* flags, TRAPS); |
|
124 |
void check_verification_type_array_size( |
|
125 |
int32_t size, int32_t max_size, TRAPS) { |
|
126 |
if (size < 0 || size > max_size) { |
|
127 |
// Since this error could be caused someone rewriting the method |
|
128 |
// but not knowing to update the stackmap data, we call the the |
|
129 |
// verifier's error method, which may not throw an exception and |
|
130 |
// failover to the old verifier instead. |
|
131 |
_verifier->class_format_error( |
|
132 |
"StackMapTable format error: bad type array size"); |
|
133 |
} |
|
134 |
} |
|
135 |
||
136 |
enum { |
|
137 |
SAME_LOCALS_1_STACK_ITEM_EXTENDED = 247, |
|
138 |
SAME_EXTENDED = 251, |
|
139 |
FULL = 255 |
|
140 |
}; |
|
141 |
||
142 |
public: |
|
143 |
// Constructor |
|
144 |
StackMapReader(ClassVerifier* v, StackMapStream* stream, char* code_data, |
|
49449
ef5d5d343e2a
8199263: Split interfaceSupport.hpp to not require including .inline.hpp files
coleenp
parents:
47216
diff
changeset
|
145 |
int32_t code_len, TRAPS); |
1 | 146 |
|
147 |
inline int32_t get_frame_count() const { return _frame_count; } |
|
148 |
StackMapFrame* next(StackMapFrame* pre_frame, bool first, |
|
149 |
u2 max_locals, u2 max_stack, TRAPS); |
|
150 |
||
151 |
void check_end(TRAPS) { |
|
152 |
if (!_stream->at_end()) { |
|
153 |
StackMapStream::stackmap_format_error("wrong attribute size", CHECK); |
|
154 |
} |
|
155 |
} |
|
156 |
}; |
|
7397 | 157 |
|
53244
9807daeb47c4
8216167: Update include guards to reflect correct directories
coleenp
parents:
49449
diff
changeset
|
158 |
#endif // SHARE_CLASSFILE_STACKMAPTABLE_HPP |