src/share/vm/prims/jvmtiRedefineClasses.hpp

Fri, 29 Apr 2016 00:06:10 +0800

author
aoqi
date
Fri, 29 Apr 2016 00:06:10 +0800
changeset 1
2d8a650513c2
parent 0
f90c822e73f8
child 431
d0d2bca037a9
child 6876
710a3c8b516e
permissions
-rw-r--r--

Added MIPS 64-bit port.

aoqi@0 1 /*
aoqi@0 2 * Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved.
aoqi@0 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
aoqi@0 4 *
aoqi@0 5 * This code is free software; you can redistribute it and/or modify it
aoqi@0 6 * under the terms of the GNU General Public License version 2 only, as
aoqi@0 7 * published by the Free Software Foundation.
aoqi@0 8 *
aoqi@0 9 * This code is distributed in the hope that it will be useful, but WITHOUT
aoqi@0 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
aoqi@0 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
aoqi@0 12 * version 2 for more details (a copy is included in the LICENSE file that
aoqi@0 13 * accompanied this code).
aoqi@0 14 *
aoqi@0 15 * You should have received a copy of the GNU General Public License version
aoqi@0 16 * 2 along with this work; if not, write to the Free Software Foundation,
aoqi@0 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
aoqi@0 18 *
aoqi@0 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
aoqi@0 20 * or visit www.oracle.com if you need additional information or have any
aoqi@0 21 * questions.
aoqi@0 22 *
aoqi@0 23 */
aoqi@0 24
aoqi@1 25 /*
aoqi@1 26 * This file has been modified by Loongson Technology in 2015. These
aoqi@1 27 * modifications are Copyright (c) 2015 Loongson Technology, and are made
aoqi@1 28 * available on the same license terms set forth above.
aoqi@1 29 */
aoqi@1 30
aoqi@0 31 #ifndef SHARE_VM_PRIMS_JVMTIREDEFINECLASSES_HPP
aoqi@0 32 #define SHARE_VM_PRIMS_JVMTIREDEFINECLASSES_HPP
aoqi@0 33
aoqi@0 34 #include "jvmtifiles/jvmtiEnv.hpp"
aoqi@0 35 #include "memory/oopFactory.hpp"
aoqi@0 36 #include "memory/resourceArea.hpp"
aoqi@0 37 #include "oops/objArrayKlass.hpp"
aoqi@0 38 #include "oops/objArrayOop.hpp"
aoqi@0 39 #include "prims/jvmtiRedefineClassesTrace.hpp"
aoqi@0 40 #include "runtime/vm_operations.hpp"
aoqi@1 41 #include "prims/jvmtiThreadState.hpp"
aoqi@0 42
aoqi@0 43 // Introduction:
aoqi@0 44 //
aoqi@0 45 // The RedefineClasses() API is used to change the definition of one or
aoqi@0 46 // more classes. While the API supports redefining more than one class
aoqi@0 47 // in a single call, in general, the API is discussed in the context of
aoqi@0 48 // changing the definition of a single current class to a single new
aoqi@0 49 // class. For clarity, the current class is will always be called
aoqi@0 50 // "the_class" and the new class will always be called "scratch_class".
aoqi@0 51 //
aoqi@0 52 // The name "the_class" is used because there is only one structure
aoqi@0 53 // that represents a specific class; redefinition does not replace the
aoqi@0 54 // structure, but instead replaces parts of the structure. The name
aoqi@0 55 // "scratch_class" is used because the structure that represents the
aoqi@0 56 // new definition of a specific class is simply used to carry around
aoqi@0 57 // the parts of the new definition until they are used to replace the
aoqi@0 58 // appropriate parts in the_class. Once redefinition of a class is
aoqi@0 59 // complete, scratch_class is thrown away.
aoqi@0 60 //
aoqi@0 61 //
aoqi@0 62 // Implementation Overview:
aoqi@0 63 //
aoqi@0 64 // The RedefineClasses() API is mostly a wrapper around the VM op that
aoqi@0 65 // does the real work. The work is split in varying degrees between
aoqi@0 66 // doit_prologue(), doit() and doit_epilogue().
aoqi@0 67 //
aoqi@0 68 // 1) doit_prologue() is called by the JavaThread on the way to a
aoqi@0 69 // safepoint. It does parameter verification and loads scratch_class
aoqi@0 70 // which involves:
aoqi@0 71 // - parsing the incoming class definition using the_class' class
aoqi@0 72 // loader and security context
aoqi@0 73 // - linking scratch_class
aoqi@0 74 // - merging constant pools and rewriting bytecodes as needed
aoqi@0 75 // for the merged constant pool
aoqi@0 76 // - verifying the bytecodes in scratch_class
aoqi@0 77 // - setting up the constant pool cache and rewriting bytecodes
aoqi@0 78 // as needed to use the cache
aoqi@0 79 // - finally, scratch_class is compared to the_class to verify
aoqi@0 80 // that it is a valid replacement class
aoqi@0 81 // - if everything is good, then scratch_class is saved in an
aoqi@0 82 // instance field in the VM operation for the doit() call
aoqi@0 83 //
aoqi@0 84 // Note: A JavaThread must do the above work.
aoqi@0 85 //
aoqi@0 86 // 2) doit() is called by the VMThread during a safepoint. It installs
aoqi@0 87 // the new class definition(s) which involves:
aoqi@0 88 // - retrieving the scratch_class from the instance field in the
aoqi@0 89 // VM operation
aoqi@0 90 // - house keeping (flushing breakpoints and caches, deoptimizing
aoqi@0 91 // dependent compiled code)
aoqi@0 92 // - replacing parts in the_class with parts from scratch_class
aoqi@0 93 // - adding weak reference(s) to track the obsolete but interesting
aoqi@0 94 // parts of the_class
aoqi@0 95 // - adjusting constant pool caches and vtables in other classes
aoqi@0 96 // that refer to methods in the_class. These adjustments use the
aoqi@0 97 // ClassLoaderDataGraph::classes_do() facility which only allows
aoqi@0 98 // a helper method to be specified. The interesting parameters
aoqi@0 99 // that we would like to pass to the helper method are saved in
aoqi@0 100 // static global fields in the VM operation.
aoqi@0 101 // - telling the SystemDictionary to notice our changes
aoqi@0 102 //
aoqi@0 103 // Note: the above work must be done by the VMThread to be safe.
aoqi@0 104 //
aoqi@0 105 // 3) doit_epilogue() is called by the JavaThread after the VM op
aoqi@0 106 // is finished and the safepoint is done. It simply cleans up
aoqi@0 107 // memory allocated in doit_prologue() and used in doit().
aoqi@0 108 //
aoqi@0 109 //
aoqi@0 110 // Constant Pool Details:
aoqi@0 111 //
aoqi@0 112 // When the_class is redefined, we cannot just replace the constant
aoqi@0 113 // pool in the_class with the constant pool from scratch_class because
aoqi@0 114 // that could confuse obsolete methods that may still be running.
aoqi@0 115 // Instead, the constant pool from the_class, old_cp, is merged with
aoqi@0 116 // the constant pool from scratch_class, scratch_cp. The resulting
aoqi@0 117 // constant pool, merge_cp, replaces old_cp in the_class.
aoqi@0 118 //
aoqi@0 119 // The key part of any merging algorithm is the entry comparison
aoqi@0 120 // function so we have to know the types of entries in a constant pool
aoqi@0 121 // in order to merge two of them together. Constant pools can contain
aoqi@0 122 // up to 12 different kinds of entries; the JVM_CONSTANT_Unicode entry
aoqi@0 123 // is not presently used so we only have to worry about the other 11
aoqi@0 124 // entry types. For the purposes of constant pool merging, it is
aoqi@0 125 // helpful to know that the 11 entry types fall into 3 different
aoqi@0 126 // subtypes: "direct", "indirect" and "double-indirect".
aoqi@0 127 //
aoqi@0 128 // Direct CP entries contain data and do not contain references to
aoqi@0 129 // other CP entries. The following are direct CP entries:
aoqi@0 130 // JVM_CONSTANT_{Double,Float,Integer,Long,Utf8}
aoqi@0 131 //
aoqi@0 132 // Indirect CP entries contain 1 or 2 references to a direct CP entry
aoqi@0 133 // and no other data. The following are indirect CP entries:
aoqi@0 134 // JVM_CONSTANT_{Class,NameAndType,String}
aoqi@0 135 //
aoqi@0 136 // Double-indirect CP entries contain two references to indirect CP
aoqi@0 137 // entries and no other data. The following are double-indirect CP
aoqi@0 138 // entries:
aoqi@0 139 // JVM_CONSTANT_{Fieldref,InterfaceMethodref,Methodref}
aoqi@0 140 //
aoqi@0 141 // When comparing entries between two constant pools, the entry types
aoqi@0 142 // are compared first and if they match, then further comparisons are
aoqi@0 143 // made depending on the entry subtype. Comparing direct CP entries is
aoqi@0 144 // simply a matter of comparing the data associated with each entry.
aoqi@0 145 // Comparing both indirect and double-indirect CP entries requires
aoqi@0 146 // recursion.
aoqi@0 147 //
aoqi@0 148 // Fortunately, the recursive combinations are limited because indirect
aoqi@0 149 // CP entries can only refer to direct CP entries and double-indirect
aoqi@0 150 // CP entries can only refer to indirect CP entries. The following is
aoqi@0 151 // an example illustration of the deepest set of indirections needed to
aoqi@0 152 // access the data associated with a JVM_CONSTANT_Fieldref entry:
aoqi@0 153 //
aoqi@0 154 // JVM_CONSTANT_Fieldref {
aoqi@0 155 // class_index => JVM_CONSTANT_Class {
aoqi@0 156 // name_index => JVM_CONSTANT_Utf8 {
aoqi@0 157 // <data-1>
aoqi@0 158 // }
aoqi@0 159 // }
aoqi@0 160 // name_and_type_index => JVM_CONSTANT_NameAndType {
aoqi@0 161 // name_index => JVM_CONSTANT_Utf8 {
aoqi@0 162 // <data-2>
aoqi@0 163 // }
aoqi@0 164 // descriptor_index => JVM_CONSTANT_Utf8 {
aoqi@0 165 // <data-3>
aoqi@0 166 // }
aoqi@0 167 // }
aoqi@0 168 // }
aoqi@0 169 //
aoqi@0 170 // The above illustration is not a data structure definition for any
aoqi@0 171 // computer language. The curly braces ('{' and '}') are meant to
aoqi@0 172 // delimit the context of the "fields" in the CP entry types shown.
aoqi@0 173 // Each indirection from the JVM_CONSTANT_Fieldref entry is shown via
aoqi@0 174 // "=>", e.g., the class_index is used to indirectly reference a
aoqi@0 175 // JVM_CONSTANT_Class entry where the name_index is used to indirectly
aoqi@0 176 // reference a JVM_CONSTANT_Utf8 entry which contains the interesting
aoqi@0 177 // <data-1>. In order to understand a JVM_CONSTANT_Fieldref entry, we
aoqi@0 178 // have to do a total of 5 indirections just to get to the CP entries
aoqi@0 179 // that contain the interesting pieces of data and then we have to
aoqi@0 180 // fetch the three pieces of data. This means we have to do a total of
aoqi@0 181 // (5 + 3) * 2 == 16 dereferences to compare two JVM_CONSTANT_Fieldref
aoqi@0 182 // entries.
aoqi@0 183 //
aoqi@0 184 // Here is the indirection, data and dereference count for each entry
aoqi@0 185 // type:
aoqi@0 186 //
aoqi@0 187 // JVM_CONSTANT_Class 1 indir, 1 data, 2 derefs
aoqi@0 188 // JVM_CONSTANT_Double 0 indir, 1 data, 1 deref
aoqi@0 189 // JVM_CONSTANT_Fieldref 2 indir, 3 data, 8 derefs
aoqi@0 190 // JVM_CONSTANT_Float 0 indir, 1 data, 1 deref
aoqi@0 191 // JVM_CONSTANT_Integer 0 indir, 1 data, 1 deref
aoqi@0 192 // JVM_CONSTANT_InterfaceMethodref 2 indir, 3 data, 8 derefs
aoqi@0 193 // JVM_CONSTANT_Long 0 indir, 1 data, 1 deref
aoqi@0 194 // JVM_CONSTANT_Methodref 2 indir, 3 data, 8 derefs
aoqi@0 195 // JVM_CONSTANT_NameAndType 1 indir, 2 data, 4 derefs
aoqi@0 196 // JVM_CONSTANT_String 1 indir, 1 data, 2 derefs
aoqi@0 197 // JVM_CONSTANT_Utf8 0 indir, 1 data, 1 deref
aoqi@0 198 //
aoqi@0 199 // So different subtypes of CP entries require different amounts of
aoqi@0 200 // work for a proper comparison.
aoqi@0 201 //
aoqi@0 202 // Now that we've talked about the different entry types and how to
aoqi@0 203 // compare them we need to get back to merging. This is not a merge in
aoqi@0 204 // the "sort -u" sense or even in the "sort" sense. When we merge two
aoqi@0 205 // constant pools, we copy all the entries from old_cp to merge_cp,
aoqi@0 206 // preserving entry order. Next we append all the unique entries from
aoqi@0 207 // scratch_cp to merge_cp and we track the index changes from the
aoqi@0 208 // location in scratch_cp to the possibly new location in merge_cp.
aoqi@0 209 // When we are done, any obsolete code that is still running that
aoqi@0 210 // uses old_cp should not be able to observe any difference if it
aoqi@0 211 // were to use merge_cp. As for the new code in scratch_class, it is
aoqi@0 212 // modified to use the appropriate index values in merge_cp before it
aoqi@0 213 // is used to replace the code in the_class.
aoqi@0 214 //
aoqi@0 215 // There is one small complication in copying the entries from old_cp
aoqi@0 216 // to merge_cp. Two of the CP entry types are special in that they are
aoqi@0 217 // lazily resolved. Before explaining the copying complication, we need
aoqi@0 218 // to digress into CP entry resolution.
aoqi@0 219 //
aoqi@0 220 // JVM_CONSTANT_Class entries are present in the class file, but are not
aoqi@0 221 // stored in memory as such until they are resolved. The entries are not
aoqi@0 222 // resolved unless they are used because resolution is expensive. During class
aoqi@0 223 // file parsing the entries are initially stored in memory as
aoqi@0 224 // JVM_CONSTANT_ClassIndex and JVM_CONSTANT_StringIndex entries. These special
aoqi@0 225 // CP entry types indicate that the JVM_CONSTANT_Class and JVM_CONSTANT_String
aoqi@0 226 // entries have been parsed, but the index values in the entries have not been
aoqi@0 227 // validated. After the entire constant pool has been parsed, the index
aoqi@0 228 // values can be validated and then the entries are converted into
aoqi@0 229 // JVM_CONSTANT_UnresolvedClass and JVM_CONSTANT_String
aoqi@0 230 // entries. During this conversion process, the UTF8 values that are
aoqi@0 231 // indirectly referenced by the JVM_CONSTANT_ClassIndex and
aoqi@0 232 // JVM_CONSTANT_StringIndex entries are changed into Symbol*s and the
aoqi@0 233 // entries are modified to refer to the Symbol*s. This optimization
aoqi@0 234 // eliminates one level of indirection for those two CP entry types and
aoqi@0 235 // gets the entries ready for verification. Verification expects to
aoqi@0 236 // find JVM_CONSTANT_UnresolvedClass but not JVM_CONSTANT_Class entries.
aoqi@0 237 //
aoqi@0 238 // Now we can get back to the copying complication. When we copy
aoqi@0 239 // entries from old_cp to merge_cp, we have to revert any
aoqi@0 240 // JVM_CONSTANT_Class entries to JVM_CONSTANT_UnresolvedClass entries
aoqi@0 241 // or verification will fail.
aoqi@0 242 //
aoqi@0 243 // It is important to explicitly state that the merging algorithm
aoqi@0 244 // effectively unresolves JVM_CONSTANT_Class entries that were in the
aoqi@0 245 // old_cp when they are changed into JVM_CONSTANT_UnresolvedClass
aoqi@0 246 // entries in the merge_cp. This is done both to make verification
aoqi@0 247 // happy and to avoid adding more brittleness between RedefineClasses
aoqi@0 248 // and the constant pool cache. By allowing the constant pool cache
aoqi@0 249 // implementation to (re)resolve JVM_CONSTANT_UnresolvedClass entries
aoqi@0 250 // into JVM_CONSTANT_Class entries, we avoid having to embed knowledge
aoqi@0 251 // about those algorithms in RedefineClasses.
aoqi@0 252 //
aoqi@0 253 // Appending unique entries from scratch_cp to merge_cp is straight
aoqi@0 254 // forward for direct CP entries and most indirect CP entries. For the
aoqi@0 255 // indirect CP entry type JVM_CONSTANT_NameAndType and for the double-
aoqi@0 256 // indirect CP entry types, the presence of more than one piece of
aoqi@0 257 // interesting data makes appending the entries more complicated.
aoqi@0 258 //
aoqi@0 259 // For the JVM_CONSTANT_{Double,Float,Integer,Long,Utf8} entry types,
aoqi@0 260 // the entry is simply copied from scratch_cp to the end of merge_cp.
aoqi@0 261 // If the index in scratch_cp is different than the destination index
aoqi@0 262 // in merge_cp, then the change in index value is tracked.
aoqi@0 263 //
aoqi@0 264 // Note: the above discussion for the direct CP entries also applies
aoqi@0 265 // to the JVM_CONSTANT_UnresolvedClass entry types.
aoqi@0 266 //
aoqi@0 267 // For the JVM_CONSTANT_Class entry types, since there is only
aoqi@0 268 // one data element at the end of the recursion, we know that we have
aoqi@0 269 // either one or two unique entries. If the JVM_CONSTANT_Utf8 entry is
aoqi@0 270 // unique then it is appended to merge_cp before the current entry.
aoqi@0 271 // If the JVM_CONSTANT_Utf8 entry is not unique, then the current entry
aoqi@0 272 // is updated to refer to the duplicate entry in merge_cp before it is
aoqi@0 273 // appended to merge_cp. Again, any changes in index values are tracked
aoqi@0 274 // as needed.
aoqi@0 275 //
aoqi@0 276 // Note: the above discussion for JVM_CONSTANT_Class entry
aoqi@0 277 // types is theoretical. Since those entry types have already been
aoqi@0 278 // optimized into JVM_CONSTANT_UnresolvedClass entry types,
aoqi@0 279 // they are handled as direct CP entries.
aoqi@0 280 //
aoqi@0 281 // For the JVM_CONSTANT_NameAndType entry type, since there are two
aoqi@0 282 // data elements at the end of the recursions, we know that we have
aoqi@0 283 // between one and three unique entries. Any unique JVM_CONSTANT_Utf8
aoqi@0 284 // entries are appended to merge_cp before the current entry. For any
aoqi@0 285 // JVM_CONSTANT_Utf8 entries that are not unique, the current entry is
aoqi@0 286 // updated to refer to the duplicate entry in merge_cp before it is
aoqi@0 287 // appended to merge_cp. Again, any changes in index values are tracked
aoqi@0 288 // as needed.
aoqi@0 289 //
aoqi@0 290 // For the JVM_CONSTANT_{Fieldref,InterfaceMethodref,Methodref} entry
aoqi@0 291 // types, since there are two indirect CP entries and three data
aoqi@0 292 // elements at the end of the recursions, we know that we have between
aoqi@0 293 // one and six unique entries. See the JVM_CONSTANT_Fieldref diagram
aoqi@0 294 // above for an example of all six entries. The uniqueness algorithm
aoqi@0 295 // for the JVM_CONSTANT_Class and JVM_CONSTANT_NameAndType entries is
aoqi@0 296 // covered above. Any unique entries are appended to merge_cp before
aoqi@0 297 // the current entry. For any entries that are not unique, the current
aoqi@0 298 // entry is updated to refer to the duplicate entry in merge_cp before
aoqi@0 299 // it is appended to merge_cp. Again, any changes in index values are
aoqi@0 300 // tracked as needed.
aoqi@0 301 //
aoqi@0 302 //
aoqi@0 303 // Other Details:
aoqi@0 304 //
aoqi@0 305 // Details for other parts of RedefineClasses need to be written.
aoqi@0 306 // This is a placeholder section.
aoqi@0 307 //
aoqi@0 308 //
aoqi@0 309 // Open Issues (in no particular order):
aoqi@0 310 //
aoqi@0 311 // - How do we serialize the RedefineClasses() API without deadlocking?
aoqi@0 312 //
aoqi@0 313 // - SystemDictionary::parse_stream() was called with a NULL protection
aoqi@0 314 // domain since the initial version. This has been changed to pass
aoqi@0 315 // the_class->protection_domain(). This change has been tested with
aoqi@0 316 // all NSK tests and nothing broke, but what will adding it now break
aoqi@0 317 // in ways that we don't test?
aoqi@0 318 //
aoqi@0 319 // - GenerateOopMap::rewrite_load_or_store() has a comment in its
aoqi@0 320 // (indirect) use of the Relocator class that the max instruction
aoqi@0 321 // size is 4 bytes. goto_w and jsr_w are 5 bytes and wide/iinc is
aoqi@0 322 // 6 bytes. Perhaps Relocator only needs a 4 byte buffer to do
aoqi@0 323 // what it does to the bytecodes. More investigation is needed.
aoqi@0 324 //
aoqi@0 325 // - How do we know if redefine_single_class() and the guts of
aoqi@0 326 // InstanceKlass are out of sync? I don't think this can be
aoqi@0 327 // automated, but we should probably order the work in
aoqi@0 328 // redefine_single_class() to match the order of field
aoqi@0 329 // definitions in InstanceKlass. We also need to add some
aoqi@0 330 // comments about keeping things in sync.
aoqi@0 331 //
aoqi@0 332 // - set_new_constant_pool() is huge and we should consider refactoring
aoqi@0 333 // it into smaller chunks of work.
aoqi@0 334 //
aoqi@0 335 // - The exception table update code in set_new_constant_pool() defines
aoqi@0 336 // const values that are also defined in a local context elsewhere.
aoqi@0 337 // The same literal values are also used in elsewhere. We need to
aoqi@0 338 // coordinate a cleanup of these constants with Runtime.
aoqi@0 339 //
aoqi@0 340
aoqi@0 341 struct JvmtiCachedClassFileData {
aoqi@0 342 jint length;
aoqi@0 343 unsigned char data[1];
aoqi@0 344 };
aoqi@0 345
aoqi@0 346 class VM_RedefineClasses: public VM_Operation {
aoqi@0 347 private:
aoqi@0 348 // These static fields are needed by ClassLoaderDataGraph::classes_do()
aoqi@0 349 // facility and the AdjustCpoolCacheAndVtable helper:
aoqi@0 350 static Array<Method*>* _old_methods;
aoqi@0 351 static Array<Method*>* _new_methods;
aoqi@0 352 static Method** _matching_old_methods;
aoqi@0 353 static Method** _matching_new_methods;
aoqi@0 354 static Method** _deleted_methods;
aoqi@0 355 static Method** _added_methods;
aoqi@0 356 static int _matching_methods_length;
aoqi@0 357 static int _deleted_methods_length;
aoqi@0 358 static int _added_methods_length;
aoqi@0 359 static Klass* _the_class_oop;
aoqi@0 360
aoqi@0 361 // The instance fields are used to pass information from
aoqi@0 362 // doit_prologue() to doit() and doit_epilogue().
aoqi@0 363 jint _class_count;
aoqi@0 364 const jvmtiClassDefinition *_class_defs; // ptr to _class_count defs
aoqi@0 365
aoqi@0 366 // This operation is used by both RedefineClasses and
aoqi@0 367 // RetransformClasses. Indicate which.
aoqi@0 368 JvmtiClassLoadKind _class_load_kind;
aoqi@0 369
aoqi@0 370 // _index_map_count is just an optimization for knowing if
aoqi@0 371 // _index_map_p contains any entries.
aoqi@0 372 int _index_map_count;
aoqi@0 373 intArray * _index_map_p;
aoqi@0 374
aoqi@0 375 // _operands_index_map_count is just an optimization for knowing if
aoqi@0 376 // _operands_index_map_p contains any entries.
aoqi@0 377 int _operands_cur_length;
aoqi@0 378 int _operands_index_map_count;
aoqi@0 379 intArray * _operands_index_map_p;
aoqi@0 380
aoqi@0 381 // ptr to _class_count scratch_classes
aoqi@0 382 Klass** _scratch_classes;
aoqi@0 383 jvmtiError _res;
aoqi@0 384
aoqi@0 385 // Performance measurement support. These timers do not cover all
aoqi@0 386 // the work done for JVM/TI RedefineClasses() but they do cover
aoqi@0 387 // the heavy lifting.
aoqi@0 388 elapsedTimer _timer_rsc_phase1;
aoqi@0 389 elapsedTimer _timer_rsc_phase2;
aoqi@0 390 elapsedTimer _timer_vm_op_prologue;
aoqi@0 391
aoqi@0 392 // These routines are roughly in call order unless otherwise noted.
aoqi@0 393
aoqi@0 394 // Load the caller's new class definition(s) into _scratch_classes.
aoqi@0 395 // Constant pool merging work is done here as needed. Also calls
aoqi@0 396 // compare_and_normalize_class_versions() to verify the class
aoqi@0 397 // definition(s).
aoqi@0 398 jvmtiError load_new_class_versions(TRAPS);
aoqi@0 399
aoqi@0 400 // Verify that the caller provided class definition(s) that meet
aoqi@0 401 // the restrictions of RedefineClasses. Normalize the order of
aoqi@0 402 // overloaded methods as needed.
aoqi@0 403 jvmtiError compare_and_normalize_class_versions(
aoqi@0 404 instanceKlassHandle the_class, instanceKlassHandle scratch_class);
aoqi@0 405
aoqi@0 406 // Figure out which new methods match old methods in name and signature,
aoqi@0 407 // which methods have been added, and which are no longer present
aoqi@0 408 void compute_added_deleted_matching_methods();
aoqi@0 409
aoqi@0 410 // Change jmethodIDs to point to the new methods
aoqi@0 411 void update_jmethod_ids();
aoqi@0 412
aoqi@0 413 // In addition to marking methods as obsolete, this routine
aoqi@0 414 // records which methods are EMCP (Equivalent Module Constant
aoqi@0 415 // Pool) in the emcp_methods BitMap and returns the number of
aoqi@0 416 // EMCP methods via emcp_method_count_p. This information is
aoqi@0 417 // used when information about the previous version of the_class
aoqi@0 418 // is squirreled away.
aoqi@0 419 void check_methods_and_mark_as_obsolete(BitMap *emcp_methods,
aoqi@0 420 int * emcp_method_count_p);
aoqi@0 421 void transfer_old_native_function_registrations(instanceKlassHandle the_class);
aoqi@0 422
aoqi@0 423 // Install the redefinition of a class
aoqi@0 424 void redefine_single_class(jclass the_jclass,
aoqi@0 425 Klass* scratch_class_oop, TRAPS);
aoqi@0 426
aoqi@0 427 void swap_annotations(instanceKlassHandle new_class,
aoqi@0 428 instanceKlassHandle scratch_class);
aoqi@0 429
aoqi@0 430 // Increment the classRedefinedCount field in the specific InstanceKlass
aoqi@0 431 // and in all direct and indirect subclasses.
aoqi@0 432 void increment_class_counter(InstanceKlass *ik, TRAPS);
aoqi@0 433
aoqi@0 434 // Support for constant pool merging (these routines are in alpha order):
aoqi@0 435 void append_entry(constantPoolHandle scratch_cp, int scratch_i,
aoqi@0 436 constantPoolHandle *merge_cp_p, int *merge_cp_length_p, TRAPS);
aoqi@0 437 void append_operand(constantPoolHandle scratch_cp, int scratch_bootstrap_spec_index,
aoqi@0 438 constantPoolHandle *merge_cp_p, int *merge_cp_length_p, TRAPS);
aoqi@0 439 void finalize_operands_merge(constantPoolHandle merge_cp, TRAPS);
aoqi@0 440 int find_or_append_indirect_entry(constantPoolHandle scratch_cp, int scratch_i,
aoqi@0 441 constantPoolHandle *merge_cp_p, int *merge_cp_length_p, TRAPS);
aoqi@0 442 int find_or_append_operand(constantPoolHandle scratch_cp, int scratch_bootstrap_spec_index,
aoqi@0 443 constantPoolHandle *merge_cp_p, int *merge_cp_length_p, TRAPS);
aoqi@0 444 int find_new_index(int old_index);
aoqi@0 445 int find_new_operand_index(int old_bootstrap_spec_index);
aoqi@0 446 bool is_unresolved_class_mismatch(constantPoolHandle cp1, int index1,
aoqi@0 447 constantPoolHandle cp2, int index2);
aoqi@0 448 void map_index(constantPoolHandle scratch_cp, int old_index, int new_index);
aoqi@0 449 void map_operand_index(int old_bootstrap_spec_index, int new_bootstrap_spec_index);
aoqi@0 450 bool merge_constant_pools(constantPoolHandle old_cp,
aoqi@0 451 constantPoolHandle scratch_cp, constantPoolHandle *merge_cp_p,
aoqi@0 452 int *merge_cp_length_p, TRAPS);
aoqi@0 453 jvmtiError merge_cp_and_rewrite(instanceKlassHandle the_class,
aoqi@0 454 instanceKlassHandle scratch_class, TRAPS);
aoqi@0 455 u2 rewrite_cp_ref_in_annotation_data(
aoqi@0 456 AnnotationArray* annotations_typeArray, int &byte_i_ref,
aoqi@0 457 const char * trace_mesg, TRAPS);
aoqi@0 458 bool rewrite_cp_refs(instanceKlassHandle scratch_class, TRAPS);
aoqi@0 459 bool rewrite_cp_refs_in_annotation_struct(
aoqi@0 460 AnnotationArray* class_annotations, int &byte_i_ref, TRAPS);
aoqi@0 461 bool rewrite_cp_refs_in_annotations_typeArray(
aoqi@0 462 AnnotationArray* annotations_typeArray, int &byte_i_ref, TRAPS);
aoqi@0 463 bool rewrite_cp_refs_in_class_annotations(
aoqi@0 464 instanceKlassHandle scratch_class, TRAPS);
aoqi@0 465 bool rewrite_cp_refs_in_element_value(
aoqi@0 466 AnnotationArray* class_annotations, int &byte_i_ref, TRAPS);
aoqi@0 467 bool rewrite_cp_refs_in_fields_annotations(
aoqi@0 468 instanceKlassHandle scratch_class, TRAPS);
aoqi@0 469 void rewrite_cp_refs_in_method(methodHandle method,
aoqi@0 470 methodHandle * new_method_p, TRAPS);
aoqi@0 471 bool rewrite_cp_refs_in_methods(instanceKlassHandle scratch_class, TRAPS);
aoqi@0 472 bool rewrite_cp_refs_in_methods_annotations(
aoqi@0 473 instanceKlassHandle scratch_class, TRAPS);
aoqi@0 474 bool rewrite_cp_refs_in_methods_default_annotations(
aoqi@0 475 instanceKlassHandle scratch_class, TRAPS);
aoqi@0 476 bool rewrite_cp_refs_in_methods_parameter_annotations(
aoqi@0 477 instanceKlassHandle scratch_class, TRAPS);
aoqi@0 478 void rewrite_cp_refs_in_stack_map_table(methodHandle method, TRAPS);
aoqi@0 479 void rewrite_cp_refs_in_verification_type_info(
aoqi@0 480 address& stackmap_addr_ref, address stackmap_end, u2 frame_i,
aoqi@0 481 u1 frame_size, TRAPS);
aoqi@0 482 void set_new_constant_pool(ClassLoaderData* loader_data,
aoqi@0 483 instanceKlassHandle scratch_class,
aoqi@0 484 constantPoolHandle scratch_cp, int scratch_cp_length, TRAPS);
aoqi@0 485
aoqi@0 486 void flush_dependent_code(instanceKlassHandle k_h, TRAPS);
aoqi@0 487
aoqi@0 488 static void dump_methods();
aoqi@0 489
aoqi@0 490 // Check that there are no old or obsolete methods
aoqi@0 491 class CheckClass : public KlassClosure {
aoqi@0 492 Thread* _thread;
aoqi@0 493 public:
aoqi@0 494 CheckClass(Thread* t) : _thread(t) {}
aoqi@0 495 void do_klass(Klass* k);
aoqi@0 496 };
aoqi@0 497
aoqi@0 498 // Unevolving classes may point to methods of the_class directly
aoqi@0 499 // from their constant pool caches, itables, and/or vtables. We
aoqi@0 500 // use the ClassLoaderDataGraph::classes_do() facility and this helper
aoqi@0 501 // to fix up these pointers.
aoqi@0 502 class AdjustCpoolCacheAndVtable : public KlassClosure {
aoqi@0 503 Thread* _thread;
aoqi@0 504 public:
aoqi@0 505 AdjustCpoolCacheAndVtable(Thread* t) : _thread(t) {}
aoqi@0 506 void do_klass(Klass* k);
aoqi@0 507 };
aoqi@0 508
aoqi@0 509 public:
aoqi@0 510 VM_RedefineClasses(jint class_count,
aoqi@0 511 const jvmtiClassDefinition *class_defs,
aoqi@0 512 JvmtiClassLoadKind class_load_kind);
aoqi@0 513 VMOp_Type type() const { return VMOp_RedefineClasses; }
aoqi@0 514 bool doit_prologue();
aoqi@0 515 void doit();
aoqi@0 516 void doit_epilogue();
aoqi@0 517
aoqi@0 518 bool allow_nested_vm_operations() const { return true; }
aoqi@0 519 jvmtiError check_error() { return _res; }
aoqi@0 520
aoqi@0 521 // Modifiable test must be shared between IsModifiableClass query
aoqi@0 522 // and redefine implementation
aoqi@0 523 static bool is_modifiable_class(oop klass_mirror);
aoqi@0 524
aoqi@0 525 static jint get_cached_class_file_len(JvmtiCachedClassFileData *cache) {
aoqi@0 526 return cache == NULL ? 0 : cache->length;
aoqi@0 527 }
aoqi@0 528 static unsigned char * get_cached_class_file_bytes(JvmtiCachedClassFileData *cache) {
aoqi@0 529 return cache == NULL ? NULL : cache->data;
aoqi@0 530 }
aoqi@0 531 };
aoqi@0 532 #endif // SHARE_VM_PRIMS_JVMTIREDEFINECLASSES_HPP

mercurial