annotate src/share/vm/classfile/stackMapTable.cpp @ 17573:aff11567504c

8035119: Fix exceptions to bytecode verification Summary: Prevent ctor calls to super() and this() from avoidable code (try blocks, if stmts, etc.) Reviewed-by: coleenp, acorn, mschoene
author hseigel
date Mon, 17 Mar 2014 10:17:55 -0400
parents 4ee06e614636
children 2993491d47df
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1 /*
17573
aff11567504c 8035119: Fix exceptions to bytecode verification
hseigel
parents: 6605
diff changeset
2 * Copyright (c) 2003, 2014, 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: 1769
diff changeset
25 #include "precompiled.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1769
diff changeset
26 #include "classfile/stackMapTable.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1769
diff changeset
27 #include "classfile/verifier.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1769
diff changeset
28 #include "memory/resourceArea.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1769
diff changeset
29 #include "oops/oop.inline.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1769
diff changeset
30 #include "runtime/fieldType.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1769
diff changeset
31 #include "runtime/handles.inline.hpp"
0
a61af66fc99e Initial load
duke
parents:
diff changeset
32
a61af66fc99e Initial load
duke
parents:
diff changeset
33 StackMapTable::StackMapTable(StackMapReader* reader, StackMapFrame* init_frame,
a61af66fc99e Initial load
duke
parents:
diff changeset
34 u2 max_locals, u2 max_stack,
a61af66fc99e Initial load
duke
parents:
diff changeset
35 char* code_data, int code_len, TRAPS) {
a61af66fc99e Initial load
duke
parents:
diff changeset
36 _code_length = code_len;
a61af66fc99e Initial load
duke
parents:
diff changeset
37 _frame_count = reader->get_frame_count();
a61af66fc99e Initial load
duke
parents:
diff changeset
38 if (_frame_count > 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
39 _frame_array = NEW_RESOURCE_ARRAY_IN_THREAD(THREAD,
a61af66fc99e Initial load
duke
parents:
diff changeset
40 StackMapFrame*, _frame_count);
a61af66fc99e Initial load
duke
parents:
diff changeset
41 StackMapFrame* pre_frame = init_frame;
a61af66fc99e Initial load
duke
parents:
diff changeset
42 for (int32_t i = 0; i < _frame_count; i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
43 StackMapFrame* frame = reader->next(
a61af66fc99e Initial load
duke
parents:
diff changeset
44 pre_frame, i == 0, max_locals, max_stack,
a61af66fc99e Initial load
duke
parents:
diff changeset
45 CHECK_VERIFY(pre_frame->verifier()));
a61af66fc99e Initial load
duke
parents:
diff changeset
46 _frame_array[i] = frame;
a61af66fc99e Initial load
duke
parents:
diff changeset
47 int offset = frame->offset();
a61af66fc99e Initial load
duke
parents:
diff changeset
48 if (offset >= code_len || code_data[offset] == 0) {
6605
4ee06e614636 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 2477
diff changeset
49 frame->verifier()->verify_error(
4ee06e614636 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 2477
diff changeset
50 ErrorContext::bad_stackmap(i, frame),
4ee06e614636 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 2477
diff changeset
51 "StackMapTable error: bad offset");
0
a61af66fc99e Initial load
duke
parents:
diff changeset
52 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
53 }
a61af66fc99e Initial load
duke
parents:
diff changeset
54 pre_frame = frame;
a61af66fc99e Initial load
duke
parents:
diff changeset
55 }
a61af66fc99e Initial load
duke
parents:
diff changeset
56 }
a61af66fc99e Initial load
duke
parents:
diff changeset
57 reader->check_end(CHECK);
a61af66fc99e Initial load
duke
parents:
diff changeset
58 }
a61af66fc99e Initial load
duke
parents:
diff changeset
59
a61af66fc99e Initial load
duke
parents:
diff changeset
60 // This method is only called by method in StackMapTable.
a61af66fc99e Initial load
duke
parents:
diff changeset
61 int StackMapTable::get_index_from_offset(int32_t offset) const {
a61af66fc99e Initial load
duke
parents:
diff changeset
62 int i = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
63 for (; i < _frame_count; i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
64 if (_frame_array[i]->offset() == offset) {
a61af66fc99e Initial load
duke
parents:
diff changeset
65 return i;
a61af66fc99e Initial load
duke
parents:
diff changeset
66 }
a61af66fc99e Initial load
duke
parents:
diff changeset
67 }
a61af66fc99e Initial load
duke
parents:
diff changeset
68 return i; // frame with offset doesn't exist in the array
a61af66fc99e Initial load
duke
parents:
diff changeset
69 }
a61af66fc99e Initial load
duke
parents:
diff changeset
70
a61af66fc99e Initial load
duke
parents:
diff changeset
71 bool StackMapTable::match_stackmap(
a61af66fc99e Initial load
duke
parents:
diff changeset
72 StackMapFrame* frame, int32_t target,
6605
4ee06e614636 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 2477
diff changeset
73 bool match, bool update, ErrorContext* ctx, TRAPS) const {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
74 int index = get_index_from_offset(target);
6605
4ee06e614636 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 2477
diff changeset
75 return match_stackmap(frame, target, index, match, update, ctx, THREAD);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
76 }
a61af66fc99e Initial load
duke
parents:
diff changeset
77
a61af66fc99e Initial load
duke
parents:
diff changeset
78 // Match and/or update current_frame to the frame in stackmap table with
a61af66fc99e Initial load
duke
parents:
diff changeset
79 // specified offset and frame index. Return true if the two frames match.
a61af66fc99e Initial load
duke
parents:
diff changeset
80 //
a61af66fc99e Initial load
duke
parents:
diff changeset
81 // The values of match and update are: _match__update_
a61af66fc99e Initial load
duke
parents:
diff changeset
82 //
a61af66fc99e Initial load
duke
parents:
diff changeset
83 // checking a branch target/exception handler: true false
a61af66fc99e Initial load
duke
parents:
diff changeset
84 // linear bytecode verification following an
a61af66fc99e Initial load
duke
parents:
diff changeset
85 // unconditional branch: false true
a61af66fc99e Initial load
duke
parents:
diff changeset
86 // linear bytecode verification not following an
a61af66fc99e Initial load
duke
parents:
diff changeset
87 // unconditional branch: true true
a61af66fc99e Initial load
duke
parents:
diff changeset
88 bool StackMapTable::match_stackmap(
a61af66fc99e Initial load
duke
parents:
diff changeset
89 StackMapFrame* frame, int32_t target, int32_t frame_index,
6605
4ee06e614636 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 2477
diff changeset
90 bool match, bool update, ErrorContext* ctx, TRAPS) const {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
91 if (frame_index < 0 || frame_index >= _frame_count) {
6605
4ee06e614636 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 2477
diff changeset
92 *ctx = ErrorContext::missing_stackmap(frame->offset());
4ee06e614636 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 2477
diff changeset
93 frame->verifier()->verify_error(
4ee06e614636 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 2477
diff changeset
94 *ctx, "Expecting a stackmap frame at branch target %d", target);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
95 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
96 }
a61af66fc99e Initial load
duke
parents:
diff changeset
97
6605
4ee06e614636 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 2477
diff changeset
98 StackMapFrame *stackmap_frame = _frame_array[frame_index];
0
a61af66fc99e Initial load
duke
parents:
diff changeset
99 bool result = true;
a61af66fc99e Initial load
duke
parents:
diff changeset
100 if (match) {
2472
7144a1d6e0a9 7030388: JCK test failed to reject invalid class check01304m10n.
kamg
parents: 2177
diff changeset
101 // when checking handler target, match == true && update == false
7144a1d6e0a9 7030388: JCK test failed to reject invalid class check01304m10n.
kamg
parents: 2177
diff changeset
102 bool is_exception_handler = !update;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
103 // Has direct control flow from last instruction, need to match the two
a61af66fc99e Initial load
duke
parents:
diff changeset
104 // frames.
6605
4ee06e614636 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 2477
diff changeset
105 result = frame->is_assignable_to(stackmap_frame, is_exception_handler,
4ee06e614636 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 2477
diff changeset
106 ctx, CHECK_VERIFY_(frame->verifier(), result));
0
a61af66fc99e Initial load
duke
parents:
diff changeset
107 }
a61af66fc99e Initial load
duke
parents:
diff changeset
108 if (update) {
a61af66fc99e Initial load
duke
parents:
diff changeset
109 // Use the frame in stackmap table as current frame
a61af66fc99e Initial load
duke
parents:
diff changeset
110 int lsize = stackmap_frame->locals_size();
a61af66fc99e Initial load
duke
parents:
diff changeset
111 int ssize = stackmap_frame->stack_size();
a61af66fc99e Initial load
duke
parents:
diff changeset
112 if (frame->locals_size() > lsize || frame->stack_size() > ssize) {
a61af66fc99e Initial load
duke
parents:
diff changeset
113 // Make sure unused type array items are all _bogus_type.
a61af66fc99e Initial load
duke
parents:
diff changeset
114 frame->reset();
a61af66fc99e Initial load
duke
parents:
diff changeset
115 }
a61af66fc99e Initial load
duke
parents:
diff changeset
116 frame->set_locals_size(lsize);
a61af66fc99e Initial load
duke
parents:
diff changeset
117 frame->copy_locals(stackmap_frame);
a61af66fc99e Initial load
duke
parents:
diff changeset
118 frame->set_stack_size(ssize);
a61af66fc99e Initial load
duke
parents:
diff changeset
119 frame->copy_stack(stackmap_frame);
a61af66fc99e Initial load
duke
parents:
diff changeset
120 frame->set_flags(stackmap_frame->flags());
a61af66fc99e Initial load
duke
parents:
diff changeset
121 }
a61af66fc99e Initial load
duke
parents:
diff changeset
122 return result;
a61af66fc99e Initial load
duke
parents:
diff changeset
123 }
a61af66fc99e Initial load
duke
parents:
diff changeset
124
a61af66fc99e Initial load
duke
parents:
diff changeset
125 void StackMapTable::check_jump_target(
a61af66fc99e Initial load
duke
parents:
diff changeset
126 StackMapFrame* frame, int32_t target, TRAPS) const {
6605
4ee06e614636 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 2477
diff changeset
127 ErrorContext ctx;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
128 bool match = match_stackmap(
6605
4ee06e614636 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 2477
diff changeset
129 frame, target, true, false, &ctx, CHECK_VERIFY(frame->verifier()));
0
a61af66fc99e Initial load
duke
parents:
diff changeset
130 if (!match || (target < 0 || target >= _code_length)) {
6605
4ee06e614636 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 2477
diff changeset
131 frame->verifier()->verify_error(ctx,
4ee06e614636 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 2477
diff changeset
132 "Inconsistent stackmap frames at branch target %d", target);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
133 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
134 }
a61af66fc99e Initial load
duke
parents:
diff changeset
135 // check if uninitialized objects exist on backward branches
a61af66fc99e Initial load
duke
parents:
diff changeset
136 check_new_object(frame, target, CHECK_VERIFY(frame->verifier()));
17573
aff11567504c 8035119: Fix exceptions to bytecode verification
hseigel
parents: 6605
diff changeset
137 frame->verifier()->update_furthest_jump(target);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
138 }
a61af66fc99e Initial load
duke
parents:
diff changeset
139
a61af66fc99e Initial load
duke
parents:
diff changeset
140 void StackMapTable::check_new_object(
a61af66fc99e Initial load
duke
parents:
diff changeset
141 const StackMapFrame* frame, int32_t target, TRAPS) const {
a61af66fc99e Initial load
duke
parents:
diff changeset
142 if (frame->offset() > target && frame->has_new_object()) {
6605
4ee06e614636 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 2477
diff changeset
143 frame->verifier()->verify_error(
4ee06e614636 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 2477
diff changeset
144 ErrorContext::bad_code(frame->offset()),
4ee06e614636 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 2477
diff changeset
145 "Uninitialized object exists on backward branch %d", target);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
146 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
147 }
a61af66fc99e Initial load
duke
parents:
diff changeset
148 }
a61af66fc99e Initial load
duke
parents:
diff changeset
149
6605
4ee06e614636 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 2477
diff changeset
150 void StackMapTable::print_on(outputStream* str) const {
4ee06e614636 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 2477
diff changeset
151 str->indent().print_cr("StackMapTable: frame_count = %d", _frame_count);
4ee06e614636 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 2477
diff changeset
152 str->indent().print_cr("table = { ");
4ee06e614636 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 2477
diff changeset
153 {
4ee06e614636 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 2477
diff changeset
154 streamIndentor si(str);
4ee06e614636 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 2477
diff changeset
155 for (int32_t i = 0; i < _frame_count; ++i) {
4ee06e614636 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 2477
diff changeset
156 _frame_array[i]->print_on(str);
4ee06e614636 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 2477
diff changeset
157 }
0
a61af66fc99e Initial load
duke
parents:
diff changeset
158 }
6605
4ee06e614636 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 2477
diff changeset
159 str->print_cr(" }");
0
a61af66fc99e Initial load
duke
parents:
diff changeset
160 }
a61af66fc99e Initial load
duke
parents:
diff changeset
161
a61af66fc99e Initial load
duke
parents:
diff changeset
162 int32_t StackMapReader::chop(
a61af66fc99e Initial load
duke
parents:
diff changeset
163 VerificationType* locals, int32_t length, int32_t chops) {
1769
1ab9e2cbfa0e 6870851: Bad frame_chop in StackMapTable crashes JVM
kamg
parents: 1552
diff changeset
164 if (locals == NULL) return -1;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
165 int32_t pos = length - 1;
a61af66fc99e Initial load
duke
parents:
diff changeset
166 for (int32_t i=0; i<chops; i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
167 if (locals[pos].is_category2_2nd()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
168 pos -= 2;
a61af66fc99e Initial load
duke
parents:
diff changeset
169 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
170 pos --;
a61af66fc99e Initial load
duke
parents:
diff changeset
171 }
a61af66fc99e Initial load
duke
parents:
diff changeset
172 if (pos<0 && i<(chops-1)) return -1;
a61af66fc99e Initial load
duke
parents:
diff changeset
173 }
a61af66fc99e Initial load
duke
parents:
diff changeset
174 return pos+1;
a61af66fc99e Initial load
duke
parents:
diff changeset
175 }
a61af66fc99e Initial load
duke
parents:
diff changeset
176
a61af66fc99e Initial load
duke
parents:
diff changeset
177 VerificationType StackMapReader::parse_verification_type(u1* flags, TRAPS) {
a61af66fc99e Initial load
duke
parents:
diff changeset
178 u1 tag = _stream->get_u1(THREAD);
a61af66fc99e Initial load
duke
parents:
diff changeset
179 if (tag < (u1)ITEM_UninitializedThis) {
a61af66fc99e Initial load
duke
parents:
diff changeset
180 return VerificationType::from_tag(tag);
a61af66fc99e Initial load
duke
parents:
diff changeset
181 }
a61af66fc99e Initial load
duke
parents:
diff changeset
182 if (tag == ITEM_Object) {
a61af66fc99e Initial load
duke
parents:
diff changeset
183 u2 class_index = _stream->get_u2(THREAD);
a61af66fc99e Initial load
duke
parents:
diff changeset
184 int nconstants = _cp->length();
a61af66fc99e Initial load
duke
parents:
diff changeset
185 if ((class_index <= 0 || class_index >= nconstants) ||
a61af66fc99e Initial load
duke
parents:
diff changeset
186 (!_cp->tag_at(class_index).is_klass() &&
a61af66fc99e Initial load
duke
parents:
diff changeset
187 !_cp->tag_at(class_index).is_unresolved_klass())) {
a61af66fc99e Initial load
duke
parents:
diff changeset
188 _stream->stackmap_format_error("bad class index", THREAD);
a61af66fc99e Initial load
duke
parents:
diff changeset
189 return VerificationType::bogus_type();
a61af66fc99e Initial load
duke
parents:
diff changeset
190 }
2177
3582bf76420e 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 1972
diff changeset
191 return VerificationType::reference_type(_cp->klass_name_at(class_index));
0
a61af66fc99e Initial load
duke
parents:
diff changeset
192 }
a61af66fc99e Initial load
duke
parents:
diff changeset
193 if (tag == ITEM_UninitializedThis) {
a61af66fc99e Initial load
duke
parents:
diff changeset
194 if (flags != NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
195 *flags |= FLAG_THIS_UNINIT;
a61af66fc99e Initial load
duke
parents:
diff changeset
196 }
a61af66fc99e Initial load
duke
parents:
diff changeset
197 return VerificationType::uninitialized_this_type();
a61af66fc99e Initial load
duke
parents:
diff changeset
198 }
a61af66fc99e Initial load
duke
parents:
diff changeset
199 if (tag == ITEM_Uninitialized) {
a61af66fc99e Initial load
duke
parents:
diff changeset
200 u2 offset = _stream->get_u2(THREAD);
a61af66fc99e Initial load
duke
parents:
diff changeset
201 if (offset >= _code_length ||
a61af66fc99e Initial load
duke
parents:
diff changeset
202 _code_data[offset] != ClassVerifier::NEW_OFFSET) {
a61af66fc99e Initial load
duke
parents:
diff changeset
203 ResourceMark rm(THREAD);
a61af66fc99e Initial load
duke
parents:
diff changeset
204 _verifier->class_format_error(
a61af66fc99e Initial load
duke
parents:
diff changeset
205 "StackMapTable format error: bad offset for Uninitialized");
a61af66fc99e Initial load
duke
parents:
diff changeset
206 return VerificationType::bogus_type();
a61af66fc99e Initial load
duke
parents:
diff changeset
207 }
a61af66fc99e Initial load
duke
parents:
diff changeset
208 return VerificationType::uninitialized_type(offset);
a61af66fc99e Initial load
duke
parents:
diff changeset
209 }
a61af66fc99e Initial load
duke
parents:
diff changeset
210 _stream->stackmap_format_error("bad verification type", THREAD);
a61af66fc99e Initial load
duke
parents:
diff changeset
211 return VerificationType::bogus_type();
a61af66fc99e Initial load
duke
parents:
diff changeset
212 }
a61af66fc99e Initial load
duke
parents:
diff changeset
213
a61af66fc99e Initial load
duke
parents:
diff changeset
214 StackMapFrame* StackMapReader::next(
a61af66fc99e Initial load
duke
parents:
diff changeset
215 StackMapFrame* pre_frame, bool first, u2 max_locals, u2 max_stack, TRAPS) {
a61af66fc99e Initial load
duke
parents:
diff changeset
216 StackMapFrame* frame;
a61af66fc99e Initial load
duke
parents:
diff changeset
217 int offset;
a61af66fc99e Initial load
duke
parents:
diff changeset
218 VerificationType* locals = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
219 u1 frame_type = _stream->get_u1(THREAD);
a61af66fc99e Initial load
duke
parents:
diff changeset
220 if (frame_type < 64) {
a61af66fc99e Initial load
duke
parents:
diff changeset
221 // same_frame
a61af66fc99e Initial load
duke
parents:
diff changeset
222 if (first) {
a61af66fc99e Initial load
duke
parents:
diff changeset
223 offset = frame_type;
a61af66fc99e Initial load
duke
parents:
diff changeset
224 // Can't share the locals array since that is updated by the verifier.
a61af66fc99e Initial load
duke
parents:
diff changeset
225 if (pre_frame->locals_size() > 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
226 locals = NEW_RESOURCE_ARRAY_IN_THREAD(
a61af66fc99e Initial load
duke
parents:
diff changeset
227 THREAD, VerificationType, pre_frame->locals_size());
a61af66fc99e Initial load
duke
parents:
diff changeset
228 }
a61af66fc99e Initial load
duke
parents:
diff changeset
229 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
230 offset = pre_frame->offset() + frame_type + 1;
a61af66fc99e Initial load
duke
parents:
diff changeset
231 locals = pre_frame->locals();
a61af66fc99e Initial load
duke
parents:
diff changeset
232 }
a61af66fc99e Initial load
duke
parents:
diff changeset
233 frame = new StackMapFrame(
a61af66fc99e Initial load
duke
parents:
diff changeset
234 offset, pre_frame->flags(), pre_frame->locals_size(), 0,
a61af66fc99e Initial load
duke
parents:
diff changeset
235 max_locals, max_stack, locals, NULL, _verifier);
a61af66fc99e Initial load
duke
parents:
diff changeset
236 if (first && locals != NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
237 frame->copy_locals(pre_frame);
a61af66fc99e Initial load
duke
parents:
diff changeset
238 }
a61af66fc99e Initial load
duke
parents:
diff changeset
239 return frame;
a61af66fc99e Initial load
duke
parents:
diff changeset
240 }
a61af66fc99e Initial load
duke
parents:
diff changeset
241 if (frame_type < 128) {
a61af66fc99e Initial load
duke
parents:
diff changeset
242 // same_locals_1_stack_item_frame
a61af66fc99e Initial load
duke
parents:
diff changeset
243 if (first) {
a61af66fc99e Initial load
duke
parents:
diff changeset
244 offset = frame_type - 64;
a61af66fc99e Initial load
duke
parents:
diff changeset
245 // Can't share the locals array since that is updated by the verifier.
a61af66fc99e Initial load
duke
parents:
diff changeset
246 if (pre_frame->locals_size() > 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
247 locals = NEW_RESOURCE_ARRAY_IN_THREAD(
a61af66fc99e Initial load
duke
parents:
diff changeset
248 THREAD, VerificationType, pre_frame->locals_size());
a61af66fc99e Initial load
duke
parents:
diff changeset
249 }
a61af66fc99e Initial load
duke
parents:
diff changeset
250 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
251 offset = pre_frame->offset() + frame_type - 63;
a61af66fc99e Initial load
duke
parents:
diff changeset
252 locals = pre_frame->locals();
a61af66fc99e Initial load
duke
parents:
diff changeset
253 }
a61af66fc99e Initial load
duke
parents:
diff changeset
254 VerificationType* stack = NEW_RESOURCE_ARRAY_IN_THREAD(
a61af66fc99e Initial load
duke
parents:
diff changeset
255 THREAD, VerificationType, 2);
a61af66fc99e Initial load
duke
parents:
diff changeset
256 u2 stack_size = 1;
a61af66fc99e Initial load
duke
parents:
diff changeset
257 stack[0] = parse_verification_type(NULL, CHECK_VERIFY_(_verifier, NULL));
a61af66fc99e Initial load
duke
parents:
diff changeset
258 if (stack[0].is_category2()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
259 stack[1] = stack[0].to_category2_2nd();
a61af66fc99e Initial load
duke
parents:
diff changeset
260 stack_size = 2;
a61af66fc99e Initial load
duke
parents:
diff changeset
261 }
a61af66fc99e Initial load
duke
parents:
diff changeset
262 check_verification_type_array_size(
a61af66fc99e Initial load
duke
parents:
diff changeset
263 stack_size, max_stack, CHECK_VERIFY_(_verifier, NULL));
a61af66fc99e Initial load
duke
parents:
diff changeset
264 frame = new StackMapFrame(
a61af66fc99e Initial load
duke
parents:
diff changeset
265 offset, pre_frame->flags(), pre_frame->locals_size(), stack_size,
a61af66fc99e Initial load
duke
parents:
diff changeset
266 max_locals, max_stack, locals, stack, _verifier);
a61af66fc99e Initial load
duke
parents:
diff changeset
267 if (first && locals != NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
268 frame->copy_locals(pre_frame);
a61af66fc99e Initial load
duke
parents:
diff changeset
269 }
a61af66fc99e Initial load
duke
parents:
diff changeset
270 return frame;
a61af66fc99e Initial load
duke
parents:
diff changeset
271 }
a61af66fc99e Initial load
duke
parents:
diff changeset
272
a61af66fc99e Initial load
duke
parents:
diff changeset
273 u2 offset_delta = _stream->get_u2(THREAD);
a61af66fc99e Initial load
duke
parents:
diff changeset
274
a61af66fc99e Initial load
duke
parents:
diff changeset
275 if (frame_type < SAME_LOCALS_1_STACK_ITEM_EXTENDED) {
a61af66fc99e Initial load
duke
parents:
diff changeset
276 // reserved frame types
a61af66fc99e Initial load
duke
parents:
diff changeset
277 _stream->stackmap_format_error(
a61af66fc99e Initial load
duke
parents:
diff changeset
278 "reserved frame type", CHECK_VERIFY_(_verifier, NULL));
a61af66fc99e Initial load
duke
parents:
diff changeset
279 }
a61af66fc99e Initial load
duke
parents:
diff changeset
280
a61af66fc99e Initial load
duke
parents:
diff changeset
281 if (frame_type == SAME_LOCALS_1_STACK_ITEM_EXTENDED) {
a61af66fc99e Initial load
duke
parents:
diff changeset
282 // same_locals_1_stack_item_frame_extended
a61af66fc99e Initial load
duke
parents:
diff changeset
283 if (first) {
a61af66fc99e Initial load
duke
parents:
diff changeset
284 offset = offset_delta;
a61af66fc99e Initial load
duke
parents:
diff changeset
285 // Can't share the locals array since that is updated by the verifier.
a61af66fc99e Initial load
duke
parents:
diff changeset
286 if (pre_frame->locals_size() > 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
287 locals = NEW_RESOURCE_ARRAY_IN_THREAD(
a61af66fc99e Initial load
duke
parents:
diff changeset
288 THREAD, VerificationType, pre_frame->locals_size());
a61af66fc99e Initial load
duke
parents:
diff changeset
289 }
a61af66fc99e Initial load
duke
parents:
diff changeset
290 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
291 offset = pre_frame->offset() + offset_delta + 1;
a61af66fc99e Initial load
duke
parents:
diff changeset
292 locals = pre_frame->locals();
a61af66fc99e Initial load
duke
parents:
diff changeset
293 }
a61af66fc99e Initial load
duke
parents:
diff changeset
294 VerificationType* stack = NEW_RESOURCE_ARRAY_IN_THREAD(
a61af66fc99e Initial load
duke
parents:
diff changeset
295 THREAD, VerificationType, 2);
a61af66fc99e Initial load
duke
parents:
diff changeset
296 u2 stack_size = 1;
a61af66fc99e Initial load
duke
parents:
diff changeset
297 stack[0] = parse_verification_type(NULL, CHECK_VERIFY_(_verifier, NULL));
a61af66fc99e Initial load
duke
parents:
diff changeset
298 if (stack[0].is_category2()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
299 stack[1] = stack[0].to_category2_2nd();
a61af66fc99e Initial load
duke
parents:
diff changeset
300 stack_size = 2;
a61af66fc99e Initial load
duke
parents:
diff changeset
301 }
a61af66fc99e Initial load
duke
parents:
diff changeset
302 check_verification_type_array_size(
a61af66fc99e Initial load
duke
parents:
diff changeset
303 stack_size, max_stack, CHECK_VERIFY_(_verifier, NULL));
a61af66fc99e Initial load
duke
parents:
diff changeset
304 frame = new StackMapFrame(
a61af66fc99e Initial load
duke
parents:
diff changeset
305 offset, pre_frame->flags(), pre_frame->locals_size(), stack_size,
a61af66fc99e Initial load
duke
parents:
diff changeset
306 max_locals, max_stack, locals, stack, _verifier);
a61af66fc99e Initial load
duke
parents:
diff changeset
307 if (first && locals != NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
308 frame->copy_locals(pre_frame);
a61af66fc99e Initial load
duke
parents:
diff changeset
309 }
a61af66fc99e Initial load
duke
parents:
diff changeset
310 return frame;
a61af66fc99e Initial load
duke
parents:
diff changeset
311 }
a61af66fc99e Initial load
duke
parents:
diff changeset
312
a61af66fc99e Initial load
duke
parents:
diff changeset
313 if (frame_type <= SAME_EXTENDED) {
a61af66fc99e Initial load
duke
parents:
diff changeset
314 // chop_frame or same_frame_extended
a61af66fc99e Initial load
duke
parents:
diff changeset
315 locals = pre_frame->locals();
a61af66fc99e Initial load
duke
parents:
diff changeset
316 int length = pre_frame->locals_size();
a61af66fc99e Initial load
duke
parents:
diff changeset
317 int chops = SAME_EXTENDED - frame_type;
a61af66fc99e Initial load
duke
parents:
diff changeset
318 int new_length = length;
a61af66fc99e Initial load
duke
parents:
diff changeset
319 u1 flags = pre_frame->flags();
a61af66fc99e Initial load
duke
parents:
diff changeset
320 if (chops != 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
321 new_length = chop(locals, length, chops);
a61af66fc99e Initial load
duke
parents:
diff changeset
322 check_verification_type_array_size(
a61af66fc99e Initial load
duke
parents:
diff changeset
323 new_length, max_locals, CHECK_VERIFY_(_verifier, NULL));
a61af66fc99e Initial load
duke
parents:
diff changeset
324 // Recompute flags since uninitializedThis could have been chopped.
a61af66fc99e Initial load
duke
parents:
diff changeset
325 flags = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
326 for (int i=0; i<new_length; i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
327 if (locals[i].is_uninitialized_this()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
328 flags |= FLAG_THIS_UNINIT;
a61af66fc99e Initial load
duke
parents:
diff changeset
329 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
330 }
a61af66fc99e Initial load
duke
parents:
diff changeset
331 }
a61af66fc99e Initial load
duke
parents:
diff changeset
332 }
a61af66fc99e Initial load
duke
parents:
diff changeset
333 if (first) {
a61af66fc99e Initial load
duke
parents:
diff changeset
334 offset = offset_delta;
a61af66fc99e Initial load
duke
parents:
diff changeset
335 // Can't share the locals array since that is updated by the verifier.
a61af66fc99e Initial load
duke
parents:
diff changeset
336 if (new_length > 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
337 locals = NEW_RESOURCE_ARRAY_IN_THREAD(
a61af66fc99e Initial load
duke
parents:
diff changeset
338 THREAD, VerificationType, new_length);
a61af66fc99e Initial load
duke
parents:
diff changeset
339 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
340 locals = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
341 }
a61af66fc99e Initial load
duke
parents:
diff changeset
342 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
343 offset = pre_frame->offset() + offset_delta + 1;
a61af66fc99e Initial load
duke
parents:
diff changeset
344 }
a61af66fc99e Initial load
duke
parents:
diff changeset
345 frame = new StackMapFrame(
a61af66fc99e Initial load
duke
parents:
diff changeset
346 offset, flags, new_length, 0, max_locals, max_stack,
a61af66fc99e Initial load
duke
parents:
diff changeset
347 locals, NULL, _verifier);
a61af66fc99e Initial load
duke
parents:
diff changeset
348 if (first && locals != NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
349 frame->copy_locals(pre_frame);
a61af66fc99e Initial load
duke
parents:
diff changeset
350 }
a61af66fc99e Initial load
duke
parents:
diff changeset
351 return frame;
a61af66fc99e Initial load
duke
parents:
diff changeset
352 } else if (frame_type < SAME_EXTENDED + 4) {
a61af66fc99e Initial load
duke
parents:
diff changeset
353 // append_frame
a61af66fc99e Initial load
duke
parents:
diff changeset
354 int appends = frame_type - SAME_EXTENDED;
a61af66fc99e Initial load
duke
parents:
diff changeset
355 int real_length = pre_frame->locals_size();
a61af66fc99e Initial load
duke
parents:
diff changeset
356 int new_length = real_length + appends*2;
a61af66fc99e Initial load
duke
parents:
diff changeset
357 locals = NEW_RESOURCE_ARRAY_IN_THREAD(THREAD, VerificationType, new_length);
a61af66fc99e Initial load
duke
parents:
diff changeset
358 VerificationType* pre_locals = pre_frame->locals();
a61af66fc99e Initial load
duke
parents:
diff changeset
359 int i;
a61af66fc99e Initial load
duke
parents:
diff changeset
360 for (i=0; i<pre_frame->locals_size(); i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
361 locals[i] = pre_locals[i];
a61af66fc99e Initial load
duke
parents:
diff changeset
362 }
a61af66fc99e Initial load
duke
parents:
diff changeset
363 u1 flags = pre_frame->flags();
a61af66fc99e Initial load
duke
parents:
diff changeset
364 for (i=0; i<appends; i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
365 locals[real_length] = parse_verification_type(&flags, THREAD);
a61af66fc99e Initial load
duke
parents:
diff changeset
366 if (locals[real_length].is_category2()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
367 locals[real_length + 1] = locals[real_length].to_category2_2nd();
a61af66fc99e Initial load
duke
parents:
diff changeset
368 ++real_length;
a61af66fc99e Initial load
duke
parents:
diff changeset
369 }
a61af66fc99e Initial load
duke
parents:
diff changeset
370 ++real_length;
a61af66fc99e Initial load
duke
parents:
diff changeset
371 }
a61af66fc99e Initial load
duke
parents:
diff changeset
372 check_verification_type_array_size(
a61af66fc99e Initial load
duke
parents:
diff changeset
373 real_length, max_locals, CHECK_VERIFY_(_verifier, NULL));
a61af66fc99e Initial load
duke
parents:
diff changeset
374 if (first) {
a61af66fc99e Initial load
duke
parents:
diff changeset
375 offset = offset_delta;
a61af66fc99e Initial load
duke
parents:
diff changeset
376 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
377 offset = pre_frame->offset() + offset_delta + 1;
a61af66fc99e Initial load
duke
parents:
diff changeset
378 }
a61af66fc99e Initial load
duke
parents:
diff changeset
379 frame = new StackMapFrame(
a61af66fc99e Initial load
duke
parents:
diff changeset
380 offset, flags, real_length, 0, max_locals,
a61af66fc99e Initial load
duke
parents:
diff changeset
381 max_stack, locals, NULL, _verifier);
a61af66fc99e Initial load
duke
parents:
diff changeset
382 return frame;
a61af66fc99e Initial load
duke
parents:
diff changeset
383 }
a61af66fc99e Initial load
duke
parents:
diff changeset
384 if (frame_type == FULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
385 // full_frame
a61af66fc99e Initial load
duke
parents:
diff changeset
386 u1 flags = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
387 u2 locals_size = _stream->get_u2(THREAD);
a61af66fc99e Initial load
duke
parents:
diff changeset
388 int real_locals_size = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
389 if (locals_size > 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
390 locals = NEW_RESOURCE_ARRAY_IN_THREAD(
a61af66fc99e Initial load
duke
parents:
diff changeset
391 THREAD, VerificationType, locals_size*2);
a61af66fc99e Initial load
duke
parents:
diff changeset
392 }
a61af66fc99e Initial load
duke
parents:
diff changeset
393 int i;
a61af66fc99e Initial load
duke
parents:
diff changeset
394 for (i=0; i<locals_size; i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
395 locals[real_locals_size] = parse_verification_type(&flags, THREAD);
a61af66fc99e Initial load
duke
parents:
diff changeset
396 if (locals[real_locals_size].is_category2()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
397 locals[real_locals_size + 1] =
a61af66fc99e Initial load
duke
parents:
diff changeset
398 locals[real_locals_size].to_category2_2nd();
a61af66fc99e Initial load
duke
parents:
diff changeset
399 ++real_locals_size;
a61af66fc99e Initial load
duke
parents:
diff changeset
400 }
a61af66fc99e Initial load
duke
parents:
diff changeset
401 ++real_locals_size;
a61af66fc99e Initial load
duke
parents:
diff changeset
402 }
a61af66fc99e Initial load
duke
parents:
diff changeset
403 check_verification_type_array_size(
a61af66fc99e Initial load
duke
parents:
diff changeset
404 real_locals_size, max_locals, CHECK_VERIFY_(_verifier, NULL));
a61af66fc99e Initial load
duke
parents:
diff changeset
405 u2 stack_size = _stream->get_u2(THREAD);
a61af66fc99e Initial load
duke
parents:
diff changeset
406 int real_stack_size = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
407 VerificationType* stack = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
408 if (stack_size > 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
409 stack = NEW_RESOURCE_ARRAY_IN_THREAD(
a61af66fc99e Initial load
duke
parents:
diff changeset
410 THREAD, VerificationType, stack_size*2);
a61af66fc99e Initial load
duke
parents:
diff changeset
411 }
a61af66fc99e Initial load
duke
parents:
diff changeset
412 for (i=0; i<stack_size; i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
413 stack[real_stack_size] = parse_verification_type(NULL, THREAD);
a61af66fc99e Initial load
duke
parents:
diff changeset
414 if (stack[real_stack_size].is_category2()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
415 stack[real_stack_size + 1] = stack[real_stack_size].to_category2_2nd();
a61af66fc99e Initial load
duke
parents:
diff changeset
416 ++real_stack_size;
a61af66fc99e Initial load
duke
parents:
diff changeset
417 }
a61af66fc99e Initial load
duke
parents:
diff changeset
418 ++real_stack_size;
a61af66fc99e Initial load
duke
parents:
diff changeset
419 }
a61af66fc99e Initial load
duke
parents:
diff changeset
420 check_verification_type_array_size(
a61af66fc99e Initial load
duke
parents:
diff changeset
421 real_stack_size, max_stack, CHECK_VERIFY_(_verifier, NULL));
a61af66fc99e Initial load
duke
parents:
diff changeset
422 if (first) {
a61af66fc99e Initial load
duke
parents:
diff changeset
423 offset = offset_delta;
a61af66fc99e Initial load
duke
parents:
diff changeset
424 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
425 offset = pre_frame->offset() + offset_delta + 1;
a61af66fc99e Initial load
duke
parents:
diff changeset
426 }
a61af66fc99e Initial load
duke
parents:
diff changeset
427 frame = new StackMapFrame(
a61af66fc99e Initial load
duke
parents:
diff changeset
428 offset, flags, real_locals_size, real_stack_size,
a61af66fc99e Initial load
duke
parents:
diff changeset
429 max_locals, max_stack, locals, stack, _verifier);
a61af66fc99e Initial load
duke
parents:
diff changeset
430 return frame;
a61af66fc99e Initial load
duke
parents:
diff changeset
431 }
a61af66fc99e Initial load
duke
parents:
diff changeset
432
a61af66fc99e Initial load
duke
parents:
diff changeset
433 _stream->stackmap_format_error(
a61af66fc99e Initial load
duke
parents:
diff changeset
434 "reserved frame type", CHECK_VERIFY_(pre_frame->verifier(), NULL));
a61af66fc99e Initial load
duke
parents:
diff changeset
435 return NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
436 }