hotspot/src/share/vm/classfile/verifier.cpp

Print this page
rev 611 : Merge
   1 #ifdef USE_PRAGMA_IDENT_SRC
   2 #pragma ident "@(#)verifier.cpp 1.113 07/05/23 10:53:19 JVM"
   3 #endif
   4 /*
   5  * Copyright 1998-2006 Sun Microsystems, Inc.  All Rights Reserved.
   6  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   7  *
   8  * This code is free software; you can redistribute it and/or modify it
   9  * under the terms of the GNU General Public License version 2 only, as
  10  * published by the Free Software Foundation.
  11  *
  12  * This code is distributed in the hope that it will be useful, but WITHOUT
  13  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  14  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  15  * version 2 for more details (a copy is included in the LICENSE file that
  16  * accompanied this code).
  17  *
  18  * You should have received a copy of the GNU General Public License version
  19  * 2 along with this work; if not, write to the Free Software Foundation,
  20  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  21  *
  22  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
  23  * CA 95054 USA or visit www.sun.com if you need additional information or
  24  * have any questions.
  25  *  


1191             verify_error(bci, "Illegal new instruction");
1192             return;
1193           }
1194           type = VerificationType::uninitialized_type(bci);
1195           current_frame.push_stack(type, CHECK_VERIFY(this));
1196           no_control_flow = false; break;
1197         }
1198         case Bytecodes::_newarray :
1199           type = get_newarray_type(bcs.get_index(), bci, CHECK_VERIFY(this));
1200           current_frame.pop_stack(
1201             VerificationType::integer_type(),  CHECK_VERIFY(this));
1202           current_frame.push_stack(type, CHECK_VERIFY(this));
1203           no_control_flow = false; break;
1204         case Bytecodes::_anewarray :
1205           verify_anewarray(
1206             bcs.get_index_big(), cp, &current_frame, CHECK_VERIFY(this));
1207           no_control_flow = false; break;
1208         case Bytecodes::_arraylength :
1209           type = current_frame.pop_stack(
1210             VerificationType::reference_check(), CHECK_VERIFY(this));
1211           if (!type.is_array()) {
1212             verify_error(bci, bad_type_msg, "arraylength");
1213           }
1214           current_frame.push_stack(
1215             VerificationType::integer_type(), CHECK_VERIFY(this));
1216           no_control_flow = false; break;
1217         case Bytecodes::_checkcast :
1218         {
1219           index = bcs.get_index_big();
1220           verify_cp_class_type(index, cp, CHECK_VERIFY(this));
1221           current_frame.pop_stack(
1222             VerificationType::reference_check(), CHECK_VERIFY(this));
1223           VerificationType klass_type = cp_index_to_type(
1224             index, cp, CHECK_VERIFY(this));
1225           current_frame.push_stack(klass_type, CHECK_VERIFY(this));
1226           no_control_flow = false; break;
1227         }
1228         case Bytecodes::_instanceof : {
1229           index = bcs.get_index_big();
1230           verify_cp_class_type(index, cp, CHECK_VERIFY(this));
1231           current_frame.pop_stack(


1586   return false;
1587 }
1588 
1589 void ClassVerifier::verify_ldc(
1590     int opcode, u2 index, StackMapFrame *current_frame,
1591      constantPoolHandle cp, u2 bci, TRAPS) {
1592   verify_cp_index(cp, index, CHECK_VERIFY(this));
1593   constantTag tag = cp->tag_at(index);
1594   unsigned int types;
1595   if (opcode == Bytecodes::_ldc || opcode == Bytecodes::_ldc_w) {
1596     if (!tag.is_unresolved_string() && !tag.is_unresolved_klass()) {
1597       types = (1 << JVM_CONSTANT_Integer) | (1 << JVM_CONSTANT_Float)
1598             | (1 << JVM_CONSTANT_String)  | (1 << JVM_CONSTANT_Class);
1599       verify_cp_type(index, cp, types, CHECK_VERIFY(this));
1600     }
1601   } else {
1602     assert(opcode == Bytecodes::_ldc2_w, "must be ldc2_w");
1603     types = (1 << JVM_CONSTANT_Double) | (1 << JVM_CONSTANT_Long);
1604     verify_cp_type(index, cp, types, CHECK_VERIFY(this));
1605   }
1606   if (tag.is_string() || tag.is_unresolved_string()) {




1607     current_frame->push_stack(
1608       VerificationType::reference_type(
1609         vmSymbols::java_lang_String()), CHECK_VERIFY(this));
1610   } else if (tag.is_klass() || tag.is_unresolved_klass()) {
1611     current_frame->push_stack(
1612       VerificationType::reference_type(
1613         vmSymbols::java_lang_Class()), CHECK_VERIFY(this));
1614   } else if (tag.is_int()) {
1615     current_frame->push_stack(
1616       VerificationType::integer_type(), CHECK_VERIFY(this));
1617   } else if (tag.is_float()) {
1618     current_frame->push_stack(
1619       VerificationType::float_type(), CHECK_VERIFY(this));
1620   } else if (tag.is_double()) {
1621     current_frame->push_stack_2(
1622       VerificationType::double_type(), 
1623       VerificationType::double2_type(), CHECK_VERIFY(this));
1624   } else if (tag.is_long()) {
1625     current_frame->push_stack_2(
1626       VerificationType::long_type(), 


   1 #ifdef USE_PRAGMA_IDENT_SRC
   2 #pragma ident "@(#)verifier.cpp 1.113 07/05/23 10:53:19 JVM"
   3 #endif
   4 /*
   5  * Copyright 1998-2008 Sun Microsystems, Inc.  All Rights Reserved.
   6  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   7  *
   8  * This code is free software; you can redistribute it and/or modify it
   9  * under the terms of the GNU General Public License version 2 only, as
  10  * published by the Free Software Foundation.
  11  *
  12  * This code is distributed in the hope that it will be useful, but WITHOUT
  13  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  14  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  15  * version 2 for more details (a copy is included in the LICENSE file that
  16  * accompanied this code).
  17  *
  18  * You should have received a copy of the GNU General Public License version
  19  * 2 along with this work; if not, write to the Free Software Foundation,
  20  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  21  *
  22  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
  23  * CA 95054 USA or visit www.sun.com if you need additional information or
  24  * have any questions.
  25  *  


1191             verify_error(bci, "Illegal new instruction");
1192             return;
1193           }
1194           type = VerificationType::uninitialized_type(bci);
1195           current_frame.push_stack(type, CHECK_VERIFY(this));
1196           no_control_flow = false; break;
1197         }
1198         case Bytecodes::_newarray :
1199           type = get_newarray_type(bcs.get_index(), bci, CHECK_VERIFY(this));
1200           current_frame.pop_stack(
1201             VerificationType::integer_type(),  CHECK_VERIFY(this));
1202           current_frame.push_stack(type, CHECK_VERIFY(this));
1203           no_control_flow = false; break;
1204         case Bytecodes::_anewarray :
1205           verify_anewarray(
1206             bcs.get_index_big(), cp, &current_frame, CHECK_VERIFY(this));
1207           no_control_flow = false; break;
1208         case Bytecodes::_arraylength :
1209           type = current_frame.pop_stack(
1210             VerificationType::reference_check(), CHECK_VERIFY(this));
1211           if (!(type.is_null() || type.is_array())) {
1212             verify_error(bci, bad_type_msg, "arraylength");
1213           }
1214           current_frame.push_stack(
1215             VerificationType::integer_type(), CHECK_VERIFY(this));
1216           no_control_flow = false; break;
1217         case Bytecodes::_checkcast :
1218         {
1219           index = bcs.get_index_big();
1220           verify_cp_class_type(index, cp, CHECK_VERIFY(this));
1221           current_frame.pop_stack(
1222             VerificationType::reference_check(), CHECK_VERIFY(this));
1223           VerificationType klass_type = cp_index_to_type(
1224             index, cp, CHECK_VERIFY(this));
1225           current_frame.push_stack(klass_type, CHECK_VERIFY(this));
1226           no_control_flow = false; break;
1227         }
1228         case Bytecodes::_instanceof : {
1229           index = bcs.get_index_big();
1230           verify_cp_class_type(index, cp, CHECK_VERIFY(this));
1231           current_frame.pop_stack(


1586   return false;
1587 }
1588 
1589 void ClassVerifier::verify_ldc(
1590     int opcode, u2 index, StackMapFrame *current_frame,
1591      constantPoolHandle cp, u2 bci, TRAPS) {
1592   verify_cp_index(cp, index, CHECK_VERIFY(this));
1593   constantTag tag = cp->tag_at(index);
1594   unsigned int types;
1595   if (opcode == Bytecodes::_ldc || opcode == Bytecodes::_ldc_w) {
1596     if (!tag.is_unresolved_string() && !tag.is_unresolved_klass()) {
1597       types = (1 << JVM_CONSTANT_Integer) | (1 << JVM_CONSTANT_Float)
1598             | (1 << JVM_CONSTANT_String)  | (1 << JVM_CONSTANT_Class);
1599       verify_cp_type(index, cp, types, CHECK_VERIFY(this));
1600     }
1601   } else {
1602     assert(opcode == Bytecodes::_ldc2_w, "must be ldc2_w");
1603     types = (1 << JVM_CONSTANT_Double) | (1 << JVM_CONSTANT_Long);
1604     verify_cp_type(index, cp, types, CHECK_VERIFY(this));
1605   }
1606   if (tag.is_string() && cp->is_pseudo_string_at(index)) {
1607     current_frame->push_stack(
1608       VerificationType::reference_type(
1609         vmSymbols::java_lang_Object()), CHECK_VERIFY(this));
1610   } else if (tag.is_string() || tag.is_unresolved_string()) {
1611     current_frame->push_stack(
1612       VerificationType::reference_type(
1613         vmSymbols::java_lang_String()), CHECK_VERIFY(this));
1614   } else if (tag.is_klass() || tag.is_unresolved_klass()) {
1615     current_frame->push_stack(
1616       VerificationType::reference_type(
1617         vmSymbols::java_lang_Class()), CHECK_VERIFY(this));
1618   } else if (tag.is_int()) {
1619     current_frame->push_stack(
1620       VerificationType::integer_type(), CHECK_VERIFY(this));
1621   } else if (tag.is_float()) {
1622     current_frame->push_stack(
1623       VerificationType::float_type(), CHECK_VERIFY(this));
1624   } else if (tag.is_double()) {
1625     current_frame->push_stack_2(
1626       VerificationType::double_type(), 
1627       VerificationType::double2_type(), CHECK_VERIFY(this));
1628   } else if (tag.is_long()) {
1629     current_frame->push_stack_2(
1630       VerificationType::long_type(),