< 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   Symbol* name;
 52   Symbol* sig;
 53   int num_uninit_fields = 0;
 54 
 55   auto find_unset = [&] (const NameAndSig& key, const bool& value) {
 56     if (!value) {
 57       name = key._name;
 58       sig = key._signature;
 59       num_uninit_fields++;
 60     }
 61   };
 62   assert_unset_fields()->iterate_all(find_unset);
 63 
 64   verifier()->verify_error(
 65     ErrorContext::bad_strict_fields(bci, this),
 66     "All strict final fields must be initialized before super(): %d field(s), %s:%s in %s",
 67     num_uninit_fields,
 68     name->as_C_string(),
 69     sig->as_C_string(),
 70     klass->name()->as_C_string()
 71   );
 72 }
 73 
 74 void StackMapFrame::print_strict_fields(AssertUnsetFieldTable* table) {
 75   ResourceMark rm;
 76   auto printfields = [&] (const NameAndSig& key, const bool& value) {
 77     log_info(verification)("Strict field: %s%s (Satisfied: %s)",
 78                            key._name->as_C_string(),
 79                            key._signature->as_C_string(),
 80                            value ? "true" : "false");
 81   };
 82   table->iterate_all(printfields);
 83 }
 84 
 85 StackMapFrame* StackMapFrame::frame_in_exception_handler(u1 flags) {
 86   Thread* thr = _verifier->thread();
 87   VerificationType* stack = NEW_RESOURCE_ARRAY_IN_THREAD(thr, VerificationType, 1);
 88   StackMapFrame* frame = new StackMapFrame(_offset, flags, _locals_size, 0,
 89                                            _max_locals, _max_stack, _locals, stack,
 90                                            _assert_unset_fields, _verifier);
 91   return frame;
 92 }
 93 
 94 void StackMapFrame::initialize_object(
 95     VerificationType old_object, VerificationType new_object) {
 96   int32_t i;
 97   for (i = 0; i < _max_locals; i++) {
 98     if (_locals[i].equals(old_object)) {
 99       _locals[i] = new_object;
100     }
101   }
102   for (i = 0; i < _stack_size; i++) {
103     if (_stack[i].equals(old_object)) {
104       _stack[i] = new_object;
105     }
106   }
107   if (old_object == VerificationType::uninitialized_this_type()) {
108     // "this" has been initialized - reset flags
109     _flags = 0;
110   }
111 }
112 
113 VerificationType StackMapFrame::set_locals_from_arg(
114     const methodHandle& m, VerificationType thisKlass) {
115   SignatureStream ss(m->signature());
116   int init_local_num = 0;
117   if (!m->is_static()) {
118     init_local_num++;
119     // add one extra argument for instance method
120     if (m->is_object_constructor() &&
121        thisKlass.name() != vmSymbols::java_lang_Object()) {
122       _locals[0] = VerificationType::uninitialized_this_type();
123       _flags |= FLAG_THIS_UNINIT;
124     } else {
125       _locals[0] = thisKlass;
126     }
127   }
128 
129   // local num may be greater than size of parameters because long/double occupies two slots
130   while(!ss.at_return_type()) {
131     init_local_num += _verifier->change_sig_to_verificationType(
132       &ss, &_locals[init_local_num]);
133     ss.next();
134   }
135   _locals_size = init_local_num;
136 
137   switch (ss.type()) {
138     case T_OBJECT:
139     case T_ARRAY:
140     {

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