hotspot/src/share/vm/classfile/classFileParser.cpp
changeset 8675 e9fef2a9bef7
parent 8653 8797d788a4f1
child 8676 9098d4e927e1
equal deleted inserted replaced
8674:303a2149d371 8675:e9fef2a9bef7
     1 /*
     1 /*
     2  * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     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
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.
     7  * published by the Free Software Foundation.
   144           cp->string_index_at_put(index, string_index);
   144           cp->string_index_at_put(index, string_index);
   145         }
   145         }
   146         break;
   146         break;
   147       case JVM_CONSTANT_MethodHandle :
   147       case JVM_CONSTANT_MethodHandle :
   148       case JVM_CONSTANT_MethodType :
   148       case JVM_CONSTANT_MethodType :
   149         if (!EnableMethodHandles ||
   149         if (_major_version < Verifier::INVOKEDYNAMIC_MAJOR_VERSION) {
   150             _major_version < Verifier::INVOKEDYNAMIC_MAJOR_VERSION) {
       
   151           classfile_parse_error(
   150           classfile_parse_error(
   152             (!EnableMethodHandles ?
   151             "Class file version does not support constant tag %u in class file %s",
   153              "This JVM does not support constant tag %u in class file %s" :
   152             tag, CHECK);
   154              "Class file version does not support constant tag %u in class file %s"),
   153         }
       
   154         if (!EnableMethodHandles) {
       
   155           classfile_parse_error(
       
   156             "This JVM does not support constant tag %u in class file %s",
   155             tag, CHECK);
   157             tag, CHECK);
   156         }
   158         }
   157         if (tag == JVM_CONSTANT_MethodHandle) {
   159         if (tag == JVM_CONSTANT_MethodHandle) {
   158           cfs->guarantee_more(4, CHECK);  // ref_kind, method_index, tag/access_flags
   160           cfs->guarantee_more(4, CHECK);  // ref_kind, method_index, tag/access_flags
   159           u1 ref_kind = cfs->get_u1_fast();
   161           u1 ref_kind = cfs->get_u1_fast();
   168         }
   170         }
   169         break;
   171         break;
   170       case JVM_CONSTANT_InvokeDynamicTrans :  // this tag appears only in old classfiles
   172       case JVM_CONSTANT_InvokeDynamicTrans :  // this tag appears only in old classfiles
   171       case JVM_CONSTANT_InvokeDynamic :
   173       case JVM_CONSTANT_InvokeDynamic :
   172         {
   174         {
   173           if (!EnableInvokeDynamic ||
   175           if (_major_version < Verifier::INVOKEDYNAMIC_MAJOR_VERSION) {
   174               _major_version < Verifier::INVOKEDYNAMIC_MAJOR_VERSION) {
       
   175             classfile_parse_error(
   176             classfile_parse_error(
   176               (!EnableInvokeDynamic ?
   177               "Class file version does not support constant tag %u in class file %s",
   177                "This JVM does not support constant tag %u in class file %s" :
   178               tag, CHECK);
   178                "Class file version does not support constant tag %u in class file %s"),
   179           }
       
   180           if (!EnableInvokeDynamic) {
       
   181             classfile_parse_error(
       
   182               "This JVM does not support constant tag %u in class file %s",
   179               tag, CHECK);
   183               tag, CHECK);
   180           }
   184           }
   181           cfs->guarantee_more(5, CHECK);  // bsm_index, nt, tag/access_flags
   185           cfs->guarantee_more(5, CHECK);  // bsm_index, nt, tag/access_flags
   182           u2 bootstrap_specifier_index = cfs->get_u2_fast();
   186           u2 bootstrap_specifier_index = cfs->get_u2_fast();
   183           u2 name_and_type_index = cfs->get_u2_fast();
   187           u2 name_and_type_index = cfs->get_u2_fast();
  2821       word_sig_index = index;
  2825       word_sig_index = index;
  2822       break;
  2826       break;
  2823     }
  2827     }
  2824   }
  2828   }
  2825 
  2829 
       
  2830   if (AllowTransitionalJSR292 && word_sig_index == 0)  return;
  2826   if (word_sig_index == 0)
  2831   if (word_sig_index == 0)
  2827     THROW_MSG(vmSymbols::java_lang_VirtualMachineError(),
  2832     THROW_MSG(vmSymbols::java_lang_VirtualMachineError(),
  2828               "missing I or J signature (for vmentry) in java.dyn.MethodHandle");
  2833               "missing I or J signature (for vmentry) in java.dyn.MethodHandle");
  2829 
  2834 
  2830   // Find vmentry field and change the signature.
  2835   // Find vmentry field and change the signature.
  2860         break;
  2865         break;
  2861       }
  2866       }
  2862     }
  2867     }
  2863   }
  2868   }
  2864 
  2869 
       
  2870   if (AllowTransitionalJSR292 && !found_vmentry)  return;
  2865   if (!found_vmentry)
  2871   if (!found_vmentry)
  2866     THROW_MSG(vmSymbols::java_lang_VirtualMachineError(),
  2872     THROW_MSG(vmSymbols::java_lang_VirtualMachineError(),
  2867               "missing vmentry byte field in java.dyn.MethodHandle");
  2873               "missing vmentry byte field in java.dyn.MethodHandle");
  2868 }
  2874 }
  2869 
  2875 
  3228     if (class_name == vmSymbols::java_lang_Class() && class_loader.is_null()) {
  3234     if (class_name == vmSymbols::java_lang_Class() && class_loader.is_null()) {
  3229       java_lang_Class_fix_pre(&methods, &fac, CHECK_(nullHandle));
  3235       java_lang_Class_fix_pre(&methods, &fac, CHECK_(nullHandle));
  3230     }
  3236     }
  3231 
  3237 
  3232     // adjust the vmentry field declaration in java.dyn.MethodHandle
  3238     // adjust the vmentry field declaration in java.dyn.MethodHandle
  3233     if (EnableMethodHandles && class_name == vmSymbols::sun_dyn_MethodHandleImpl() && class_loader.is_null()) {
  3239     if (EnableMethodHandles && class_name == vmSymbols::java_dyn_MethodHandle() && class_loader.is_null()) {
       
  3240       java_dyn_MethodHandle_fix_pre(cp, fields, &fac, CHECK_(nullHandle));
       
  3241     }
       
  3242     if (AllowTransitionalJSR292 &&
       
  3243         EnableMethodHandles && class_name == vmSymbols::sun_dyn_MethodHandleImpl() && class_loader.is_null()) {
       
  3244       // allow vmentry field in MethodHandleImpl also
  3234       java_dyn_MethodHandle_fix_pre(cp, fields, &fac, CHECK_(nullHandle));
  3245       java_dyn_MethodHandle_fix_pre(cp, fields, &fac, CHECK_(nullHandle));
  3235     }
  3246     }
  3236 
  3247 
  3237     // Add a fake "discovered" field if it is not present
  3248     // Add a fake "discovered" field if it is not present
  3238     // for compatibility with earlier jdk's.
  3249     // for compatibility with earlier jdk's.