< prev index next >

src/hotspot/share/classfile/stackMapFrame.cpp

Print this page

 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  *
 19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 20  * or visit www.oracle.com if you need additional information or have any
 21  * questions.
 22  *
 23  */
 24 
 25 #include "classfile/stackMapFrame.hpp"
 26 #include "classfile/verifier.hpp"
 27 #include "classfile/vmSymbols.hpp"
 28 #include "memory/resourceArea.hpp"
 29 #include "oops/oop.inline.hpp"
 30 #include "oops/symbol.hpp"
 31 #include "runtime/handles.inline.hpp"
 32 #include "utilities/globalDefinitions.hpp"
 33 
 34 StackMapFrame::StackMapFrame(u2 max_locals, u2 max_stack, ClassVerifier* v) :
 35                       _offset(0), _locals_size(0), _stack_size(0),
 36                       _stack_mark(0), _max_locals(max_locals),
 37                       _max_stack(max_stack), _flags(0), _verifier(v) {
 38   Thread* thr = v->thread();
 39   _locals = NEW_RESOURCE_ARRAY_IN_THREAD(thr, VerificationType, max_locals);
 40   _stack = NEW_RESOURCE_ARRAY_IN_THREAD(thr, VerificationType, max_stack);
 41   int32_t i;
 42   for(i = 0; i < max_locals; i++) {
 43     _locals[i] = VerificationType::bogus_type();
 44   }
 45   for(i = 0; i < max_stack; i++) {
 46     _stack[i] = VerificationType::bogus_type();
 47   }
 48 }
 49 







































 50 StackMapFrame* StackMapFrame::frame_in_exception_handler(u1 flags) {
 51   Thread* thr = _verifier->thread();
 52   VerificationType* stack = NEW_RESOURCE_ARRAY_IN_THREAD(thr, VerificationType, 1);
 53   StackMapFrame* frame = new StackMapFrame(_offset, flags, _locals_size, 0, _max_locals, _max_stack, _locals, stack, _verifier);


 54   return frame;
 55 }
 56 
 57 void StackMapFrame::initialize_object(
 58     VerificationType old_object, VerificationType new_object) {
 59   int32_t i;
 60   for (i = 0; i < _max_locals; i++) {
 61     if (_locals[i].equals(old_object)) {
 62       _locals[i] = new_object;
 63     }
 64   }
 65   for (i = 0; i < _stack_size; i++) {
 66     if (_stack[i].equals(old_object)) {
 67       _stack[i] = new_object;
 68     }
 69   }
 70   if (old_object == VerificationType::uninitialized_this_type()) {
 71     // "this" has been initialized - reset flags
 72     _flags = 0;
 73   }
 74 }
 75 
 76 VerificationType StackMapFrame::set_locals_from_arg(
 77     const methodHandle& m, VerificationType thisKlass) {
 78   SignatureStream ss(m->signature());
 79   int init_local_num = 0;
 80   if (!m->is_static()) {
 81     init_local_num++;
 82     // add one extra argument for instance method
 83     if (m->name() == vmSymbols::object_initializer_name() &&
 84        thisKlass.name() != vmSymbols::java_lang_Object()) {
 85       _locals[0] = VerificationType::uninitialized_this_type();
 86       _flags |= FLAG_THIS_UNINIT;
 87     } else {
 88       _locals[0] = thisKlass;
 89     }
 90   }
 91 
 92   // local num may be greater than size of parameters because long/double occupies two slots
 93   while(!ss.at_return_type()) {
 94     init_local_num += _verifier->change_sig_to_verificationType(
 95       &ss, &_locals[init_local_num]);
 96     ss.next();
 97   }
 98   _locals_size = init_local_num;
 99 
100   switch (ss.type()) {
101     case T_OBJECT:
102     case T_ARRAY:
103     {

171   // Only need to compare type elements up to target->locals() or target->stack().
172   // The remaining type elements in this state can be ignored because they are
173   // assignable to bogus type.
174   int mismatch_loc;
175   mismatch_loc = is_assignable_to(
176     _locals, target->locals(), target->locals_size(), THREAD);
177   if (mismatch_loc != target->locals_size()) {
178     *ctx = ErrorContext::bad_type(target->offset(),
179         TypeOrigin::local(mismatch_loc, (StackMapFrame*)this),
180         TypeOrigin::sm_local(mismatch_loc, (StackMapFrame*)target));
181     return false;
182   }
183   mismatch_loc = is_assignable_to(_stack, target->stack(), _stack_size, THREAD);
184   if (mismatch_loc != _stack_size) {
185     *ctx = ErrorContext::bad_type(target->offset(),
186         TypeOrigin::stack(mismatch_loc, (StackMapFrame*)this),
187         TypeOrigin::sm_stack(mismatch_loc, (StackMapFrame*)target));
188     return false;
189   }
190 










191   if ((_flags | target->flags()) == target->flags()) {
192     return true;
193   } else {
194     *ctx = ErrorContext::bad_flags(target->offset(),
195         (StackMapFrame*)this, (StackMapFrame*)target);
196     return false;
197   }
198 }
199 
200 VerificationType StackMapFrame::pop_stack_ex(VerificationType type, TRAPS) {
201   if (_stack_size <= 0) {
202     verifier()->verify_error(
203         ErrorContext::stack_underflow(_offset, this),
204         "Operand stack underflow");
205     return VerificationType::bogus_type();
206   }
207   VerificationType top = _stack[--_stack_size];
208   bool subtype = type.is_assignable_from(
209     top, verifier(), false, CHECK_(VerificationType::bogus_type()));
210   if (!subtype) {

 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  *
 19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 20  * or visit www.oracle.com if you need additional information or have any
 21  * questions.
 22  *
 23  */
 24 
 25 #include "classfile/stackMapFrame.hpp"
 26 #include "classfile/verifier.hpp"
 27 #include "classfile/vmSymbols.hpp"
 28 #include "memory/resourceArea.hpp"
 29 #include "oops/oop.inline.hpp"
 30 #include "oops/symbol.hpp"
 31 #include "runtime/handles.inline.hpp"
 32 #include "utilities/globalDefinitions.hpp"
 33 
 34 StackMapFrame::StackMapFrame(u2 max_locals, u2 max_stack, AssertUnsetFieldTable* initial_strict_fields, ClassVerifier* v) :
 35                       _offset(0), _locals_size(0), _stack_size(0),
 36                       _stack_mark(0), _max_locals(max_locals),
 37                       _max_stack(max_stack), _flags(0), _assert_unset_fields(initial_strict_fields), _verifier(v) {
 38   Thread* thr = v->thread();
 39   _locals = NEW_RESOURCE_ARRAY_IN_THREAD(thr, VerificationType, max_locals);
 40   _stack = NEW_RESOURCE_ARRAY_IN_THREAD(thr, VerificationType, max_stack);
 41   int32_t i;
 42   for(i = 0; i < max_locals; i++) {
 43     _locals[i] = VerificationType::bogus_type();
 44   }
 45   for(i = 0; i < max_stack; i++) {
 46     _stack[i] = VerificationType::bogus_type();
 47   }
 48 }
 49 
 50 void StackMapFrame::unsatisfied_strict_fields_error(InstanceKlass* klass, int bci) {
 51   // Default these to `<Unknown>` as they will be replaced with the correct
 52   // values by the `find_unset` lambda as we only call this code when
 53   // an error has already been determined.  This just provides a safe
 54   // obvious fallback value.
 55   Symbol* name = vmSymbols::unknown_class_name();
 56   Symbol* sig = vmSymbols::unknown_class_name();
 57   int num_uninit_fields = 0;
 58 
 59   auto find_unset = [&] (const NameAndSig& key, const bool& value) {
 60     if (!value) {
 61       name = key._name;
 62       sig = key._signature;
 63       num_uninit_fields++;
 64     }
 65   };
 66   assert_unset_fields()->iterate_all(find_unset);
 67 
 68   verifier()->verify_error(
 69     ErrorContext::bad_strict_fields(bci, this),
 70     "All strict final fields must be initialized before super(): %d field(s), %s:%s in %s",
 71     num_uninit_fields,
 72     name->as_C_string(),
 73     sig->as_C_string(),
 74     klass->name()->as_C_string()
 75   );
 76 }
 77 
 78 void StackMapFrame::print_strict_fields(AssertUnsetFieldTable* table) {
 79   ResourceMark rm;
 80   auto printfields = [&] (const NameAndSig& key, const bool& value) {
 81     log_info(verification)("Strict field: %s%s (Satisfied: %s)",
 82                            key._name->as_C_string(),
 83                            key._signature->as_C_string(),
 84                            value ? "true" : "false");
 85   };
 86   table->iterate_all(printfields);
 87 }
 88 
 89 StackMapFrame* StackMapFrame::frame_in_exception_handler(u1 flags) {
 90   Thread* thr = _verifier->thread();
 91   VerificationType* stack = NEW_RESOURCE_ARRAY_IN_THREAD(thr, VerificationType, 1);
 92   StackMapFrame* frame = new StackMapFrame(_offset, flags, _locals_size, 0,
 93                                            _max_locals, _max_stack, _locals, stack,
 94                                            _assert_unset_fields, _verifier);
 95   return frame;
 96 }
 97 
 98 void StackMapFrame::initialize_object(
 99     VerificationType old_object, VerificationType new_object) {
100   int32_t i;
101   for (i = 0; i < _max_locals; i++) {
102     if (_locals[i].equals(old_object)) {
103       _locals[i] = new_object;
104     }
105   }
106   for (i = 0; i < _stack_size; i++) {
107     if (_stack[i].equals(old_object)) {
108       _stack[i] = new_object;
109     }
110   }
111   if (old_object == VerificationType::uninitialized_this_type()) {
112     // "this" has been initialized - reset flags
113     _flags = 0;
114   }
115 }
116 
117 VerificationType StackMapFrame::set_locals_from_arg(
118     const methodHandle& m, VerificationType thisKlass) {
119   SignatureStream ss(m->signature());
120   int init_local_num = 0;
121   if (!m->is_static()) {
122     init_local_num++;
123     // add one extra argument for instance method
124     if (m->is_object_constructor() &&
125        thisKlass.name() != vmSymbols::java_lang_Object()) {
126       _locals[0] = VerificationType::uninitialized_this_type();
127       _flags |= FLAG_THIS_UNINIT;
128     } else {
129       _locals[0] = thisKlass;
130     }
131   }
132 
133   // local num may be greater than size of parameters because long/double occupies two slots
134   while(!ss.at_return_type()) {
135     init_local_num += _verifier->change_sig_to_verificationType(
136       &ss, &_locals[init_local_num]);
137     ss.next();
138   }
139   _locals_size = init_local_num;
140 
141   switch (ss.type()) {
142     case T_OBJECT:
143     case T_ARRAY:
144     {

212   // Only need to compare type elements up to target->locals() or target->stack().
213   // The remaining type elements in this state can be ignored because they are
214   // assignable to bogus type.
215   int mismatch_loc;
216   mismatch_loc = is_assignable_to(
217     _locals, target->locals(), target->locals_size(), THREAD);
218   if (mismatch_loc != target->locals_size()) {
219     *ctx = ErrorContext::bad_type(target->offset(),
220         TypeOrigin::local(mismatch_loc, (StackMapFrame*)this),
221         TypeOrigin::sm_local(mismatch_loc, (StackMapFrame*)target));
222     return false;
223   }
224   mismatch_loc = is_assignable_to(_stack, target->stack(), _stack_size, THREAD);
225   if (mismatch_loc != _stack_size) {
226     *ctx = ErrorContext::bad_type(target->offset(),
227         TypeOrigin::stack(mismatch_loc, (StackMapFrame*)this),
228         TypeOrigin::sm_stack(mismatch_loc, (StackMapFrame*)target));
229     return false;
230   }
231 
232   // Check that assert unset fields are compatible
233   bool compatible = verify_unset_fields_compatibility(target->assert_unset_fields());
234   if (!compatible) {
235     print_strict_fields(assert_unset_fields());
236     print_strict_fields(target->assert_unset_fields());
237     *ctx = ErrorContext::strict_fields_mismatch(target->offset(),
238         (StackMapFrame*)this, (StackMapFrame*)target);
239     return false;
240   }
241 
242   if ((_flags | target->flags()) == target->flags()) {
243     return true;
244   } else {
245     *ctx = ErrorContext::bad_flags(target->offset(),
246         (StackMapFrame*)this, (StackMapFrame*)target);
247     return false;
248   }
249 }
250 
251 VerificationType StackMapFrame::pop_stack_ex(VerificationType type, TRAPS) {
252   if (_stack_size <= 0) {
253     verifier()->verify_error(
254         ErrorContext::stack_underflow(_offset, this),
255         "Operand stack underflow");
256     return VerificationType::bogus_type();
257   }
258   VerificationType top = _stack[--_stack_size];
259   bool subtype = type.is_assignable_from(
260     top, verifier(), false, CHECK_(VerificationType::bogus_type()));
261   if (!subtype) {
< prev index next >