src/share/vm/prims/jvmtiRedefineClasses.hpp

changeset 4037
da91efe96a93
parent 2708
1d1603768966
child 4165
fb19af007ffc
     1.1 --- a/src/share/vm/prims/jvmtiRedefineClasses.hpp	Fri Aug 31 16:39:35 2012 -0700
     1.2 +++ b/src/share/vm/prims/jvmtiRedefineClasses.hpp	Sat Sep 01 13:25:18 2012 -0400
     1.3 @@ -1,5 +1,5 @@
     1.4  /*
     1.5 - * Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved.
     1.6 + * Copyright (c) 2003, 2012, Oracle and/or its affiliates. All rights reserved.
     1.7   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.8   *
     1.9   * This code is free software; you can redistribute it and/or modify it
    1.10 @@ -210,28 +210,23 @@
    1.11  // lazily resolved. Before explaining the copying complication, we need
    1.12  // to digress into CP entry resolution.
    1.13  //
    1.14 -// JVM_CONSTANT_Class and JVM_CONSTANT_String entries are present in
    1.15 -// the class file, but are not stored in memory as such until they are
    1.16 -// resolved. The entries are not resolved unless they are used because
    1.17 -// resolution is expensive. During class file parsing the entries are
    1.18 -// initially stored in memory as JVM_CONSTANT_ClassIndex and
    1.19 -// JVM_CONSTANT_StringIndex entries. These special CP entry types
    1.20 -// indicate that the JVM_CONSTANT_Class and JVM_CONSTANT_String entries
    1.21 -// have been parsed, but the index values in the entries have not been
    1.22 +// JVM_CONSTANT_Class entries are present in the class file, but are not
    1.23 +// stored in memory as such until they are resolved. The entries are not
    1.24 +// resolved unless they are used because resolution is expensive. During class
    1.25 +// file parsing the entries are initially stored in memory as
    1.26 +// JVM_CONSTANT_ClassIndex and JVM_CONSTANT_StringIndex entries. These special
    1.27 +// CP entry types indicate that the JVM_CONSTANT_Class and JVM_CONSTANT_String
    1.28 +// entries have been parsed, but the index values in the entries have not been
    1.29  // validated. After the entire constant pool has been parsed, the index
    1.30  // values can be validated and then the entries are converted into
    1.31 -// JVM_CONSTANT_UnresolvedClass and JVM_CONSTANT_UnresolvedString
    1.32 +// JVM_CONSTANT_UnresolvedClass and JVM_CONSTANT_String
    1.33  // entries. During this conversion process, the UTF8 values that are
    1.34  // indirectly referenced by the JVM_CONSTANT_ClassIndex and
    1.35  // JVM_CONSTANT_StringIndex entries are changed into Symbol*s and the
    1.36  // entries are modified to refer to the Symbol*s. This optimization
    1.37  // eliminates one level of indirection for those two CP entry types and
    1.38 -// gets the entries ready for verification. During class file parsing
    1.39 -// it is also possible for JVM_CONSTANT_UnresolvedString entries to be
    1.40 -// resolved into JVM_CONSTANT_String entries. Verification expects to
    1.41 -// find JVM_CONSTANT_UnresolvedClass and either JVM_CONSTANT_String or
    1.42 -// JVM_CONSTANT_UnresolvedString entries and not JVM_CONSTANT_Class
    1.43 -// entries.
    1.44 +// gets the entries ready for verification.  Verification expects to
    1.45 +// find JVM_CONSTANT_UnresolvedClass but not JVM_CONSTANT_Class entries.
    1.46  //
    1.47  // Now we can get back to the copying complication. When we copy
    1.48  // entries from old_cp to merge_cp, we have to revert any
    1.49 @@ -260,9 +255,9 @@
    1.50  // in merge_cp, then the change in index value is tracked.
    1.51  //
    1.52  // Note: the above discussion for the direct CP entries also applies
    1.53 -// to the JVM_CONSTANT_Unresolved{Class,String} entry types.
    1.54 +// to the JVM_CONSTANT_UnresolvedClass entry types.
    1.55  //
    1.56 -// For the JVM_CONSTANT_{Class,String} entry types, since there is only
    1.57 +// For the JVM_CONSTANT_Class entry types, since there is only
    1.58  // one data element at the end of the recursion, we know that we have
    1.59  // either one or two unique entries. If the JVM_CONSTANT_Utf8 entry is
    1.60  // unique then it is appended to merge_cp before the current entry.
    1.61 @@ -271,9 +266,9 @@
    1.62  // appended to merge_cp. Again, any changes in index values are tracked
    1.63  // as needed.
    1.64  //
    1.65 -// Note: the above discussion for JVM_CONSTANT_{Class,String} entry
    1.66 +// Note: the above discussion for JVM_CONSTANT_Class entry
    1.67  // types is theoretical. Since those entry types have already been
    1.68 -// optimized into JVM_CONSTANT_Unresolved{Class,String} entry types,
    1.69 +// optimized into JVM_CONSTANT_UnresolvedClass entry types,
    1.70  // they are handled as direct CP entries.
    1.71  //
    1.72  // For the JVM_CONSTANT_NameAndType entry type, since there are two
    1.73 @@ -320,17 +315,11 @@
    1.74  //   6 bytes. Perhaps Relocator only needs a 4 byte buffer to do
    1.75  //   what it does to the bytecodes. More investigation is needed.
    1.76  //
    1.77 -// - java.lang.Object methods can be called on arrays. This is
    1.78 -//   implemented via the arrayKlassOop vtable which we don't
    1.79 -//   update. For example, if we redefine java.lang.Object.toString(),
    1.80 -//   then the new version of the method will not be called for array
    1.81 -//   objects.
    1.82 -//
    1.83  // - How do we know if redefine_single_class() and the guts of
    1.84 -//   instanceKlass are out of sync? I don't think this can be
    1.85 +//   InstanceKlass are out of sync? I don't think this can be
    1.86  //   automated, but we should probably order the work in
    1.87  //   redefine_single_class() to match the order of field
    1.88 -//   definitions in instanceKlass. We also need to add some
    1.89 +//   definitions in InstanceKlass. We also need to add some
    1.90  //   comments about keeping things in sync.
    1.91  //
    1.92  // - set_new_constant_pool() is huge and we should consider refactoring
    1.93 @@ -346,16 +335,16 @@
    1.94   private:
    1.95    // These static fields are needed by SystemDictionary::classes_do()
    1.96    // facility and the adjust_cpool_cache_and_vtable() helper:
    1.97 -  static objArrayOop     _old_methods;
    1.98 -  static objArrayOop     _new_methods;
    1.99 -  static methodOop*      _matching_old_methods;
   1.100 -  static methodOop*      _matching_new_methods;
   1.101 -  static methodOop*      _deleted_methods;
   1.102 -  static methodOop*      _added_methods;
   1.103 +  static Array<Method*>* _old_methods;
   1.104 +  static Array<Method*>* _new_methods;
   1.105 +  static Method**      _matching_old_methods;
   1.106 +  static Method**      _matching_new_methods;
   1.107 +  static Method**      _deleted_methods;
   1.108 +  static Method**      _added_methods;
   1.109    static int             _matching_methods_length;
   1.110    static int             _deleted_methods_length;
   1.111    static int             _added_methods_length;
   1.112 -  static klassOop        _the_class_oop;
   1.113 +  static Klass*          _the_class_oop;
   1.114  
   1.115    // The instance fields are used to pass information from
   1.116    // doit_prologue() to doit() and doit_epilogue().
   1.117 @@ -371,7 +360,7 @@
   1.118    int                         _index_map_count;
   1.119    intArray *                  _index_map_p;
   1.120    // ptr to _class_count scratch_classes
   1.121 -  instanceKlassHandle *       _scratch_classes;
   1.122 +  Klass**                   _scratch_classes;
   1.123    jvmtiError                  _res;
   1.124  
   1.125    // Performance measurement support. These timers do not cover all
   1.126 @@ -398,7 +387,7 @@
   1.127    // Swap annotations[i] with annotations[j]
   1.128    // Used by compare_and_normalize_class_versions() when normalizing
   1.129    // overloaded methods or changing idnum as when adding or deleting methods.
   1.130 -  void swap_all_method_annotations(int i, int j, instanceKlassHandle scratch_class);
   1.131 +  void swap_all_method_annotations(int i, int j, instanceKlassHandle scratch_class, TRAPS);
   1.132  
   1.133    // Figure out which new methods match old methods in name and signature,
   1.134    // which methods have been added, and which are no longer present
   1.135 @@ -421,15 +410,16 @@
   1.136    // from their constant pool caches, itables, and/or vtables. We
   1.137    // use the SystemDictionary::classes_do() facility and this helper
   1.138    // to fix up these pointers.
   1.139 -  static void adjust_cpool_cache_and_vtable(klassOop k_oop, oop loader, TRAPS);
   1.140 +  static void adjust_cpool_cache_and_vtable(Klass* k_oop, ClassLoaderData* initiating_loader, TRAPS);
   1.141 +  static void adjust_array_vtable(Klass* k_oop);
   1.142  
   1.143    // Install the redefinition of a class
   1.144    void redefine_single_class(jclass the_jclass,
   1.145 -    instanceKlassHandle scratch_class, TRAPS);
   1.146 +    Klass* scratch_class_oop, TRAPS);
   1.147  
   1.148 -  // Increment the classRedefinedCount field in the specific instanceKlass
   1.149 +  // Increment the classRedefinedCount field in the specific InstanceKlass
   1.150    // and in all direct and indirect subclasses.
   1.151 -  void increment_class_counter(instanceKlass *ik, TRAPS);
   1.152 +  void increment_class_counter(InstanceKlass *ik, TRAPS);
   1.153  
   1.154    // Support for constant pool merging (these routines are in alpha
   1.155    // order):
   1.156 @@ -438,8 +428,6 @@
   1.157    int find_new_index(int old_index);
   1.158    bool is_unresolved_class_mismatch(constantPoolHandle cp1, int index1,
   1.159      constantPoolHandle cp2, int index2);
   1.160 -  bool is_unresolved_string_mismatch(constantPoolHandle cp1, int index1,
   1.161 -    constantPoolHandle cp2, int index2);
   1.162    void map_index(constantPoolHandle scratch_cp, int old_index, int new_index);
   1.163    bool merge_constant_pools(constantPoolHandle old_cp,
   1.164      constantPoolHandle scratch_cp, constantPoolHandle *merge_cp_p,
   1.165 @@ -447,17 +435,17 @@
   1.166    jvmtiError merge_cp_and_rewrite(instanceKlassHandle the_class,
   1.167      instanceKlassHandle scratch_class, TRAPS);
   1.168    u2 rewrite_cp_ref_in_annotation_data(
   1.169 -    typeArrayHandle annotations_typeArray, int &byte_i_ref,
   1.170 +    AnnotationArray* annotations_typeArray, int &byte_i_ref,
   1.171      const char * trace_mesg, TRAPS);
   1.172    bool rewrite_cp_refs(instanceKlassHandle scratch_class, TRAPS);
   1.173    bool rewrite_cp_refs_in_annotation_struct(
   1.174 -    typeArrayHandle class_annotations, int &byte_i_ref, TRAPS);
   1.175 +    AnnotationArray* class_annotations, int &byte_i_ref, TRAPS);
   1.176    bool rewrite_cp_refs_in_annotations_typeArray(
   1.177 -    typeArrayHandle annotations_typeArray, int &byte_i_ref, TRAPS);
   1.178 +    AnnotationArray* annotations_typeArray, int &byte_i_ref, TRAPS);
   1.179    bool rewrite_cp_refs_in_class_annotations(
   1.180      instanceKlassHandle scratch_class, TRAPS);
   1.181    bool rewrite_cp_refs_in_element_value(
   1.182 -    typeArrayHandle class_annotations, int &byte_i_ref, TRAPS);
   1.183 +    AnnotationArray* class_annotations, int &byte_i_ref, TRAPS);
   1.184    bool rewrite_cp_refs_in_fields_annotations(
   1.185      instanceKlassHandle scratch_class, TRAPS);
   1.186    void rewrite_cp_refs_in_method(methodHandle method,
   1.187 @@ -473,12 +461,13 @@
   1.188    void rewrite_cp_refs_in_verification_type_info(
   1.189           address& stackmap_addr_ref, address stackmap_end, u2 frame_i,
   1.190           u1 frame_size, TRAPS);
   1.191 -  void set_new_constant_pool(instanceKlassHandle scratch_class,
   1.192 -    constantPoolHandle scratch_cp, int scratch_cp_length, bool shrink, TRAPS);
   1.193 +  void set_new_constant_pool(ClassLoaderData* loader_data,
   1.194 +         instanceKlassHandle scratch_class,
   1.195 +         constantPoolHandle scratch_cp, int scratch_cp_length, TRAPS);
   1.196  
   1.197    void flush_dependent_code(instanceKlassHandle k_h, TRAPS);
   1.198  
   1.199 -  static void check_class(klassOop k_oop, oop initiating_loader, TRAPS) PRODUCT_RETURN;
   1.200 +  static void check_class(Klass* k_oop, ClassLoaderData* initiating_loader, TRAPS) PRODUCT_RETURN;
   1.201  
   1.202    static void dump_methods()   PRODUCT_RETURN;
   1.203  
   1.204 @@ -499,4 +488,16 @@
   1.205    static bool is_modifiable_class(oop klass_mirror);
   1.206  };
   1.207  
   1.208 +
   1.209 +// Helper class to mark and unmark metadata used on the stack as either handles
   1.210 +// or executing methods, so that it can't be deleted during class redefinition
   1.211 +// and class unloading.
   1.212 +class MetadataOnStackMark : public StackObj {
   1.213 +  NOT_PRODUCT(static bool _is_active;)
   1.214 + public:
   1.215 +  MetadataOnStackMark();
   1.216 +  ~MetadataOnStackMark();
   1.217 +  static void record(Metadata* m);
   1.218 +};
   1.219 +
   1.220  #endif // SHARE_VM_PRIMS_JVMTIREDEFINECLASSES_HPP

mercurial