src/hotspot/share/classfile/klassFactory.cpp
author egahlin
Tue, 15 May 2018 20:24:34 +0200
changeset 50113 caf115bb98ad
parent 50039 9fec54fe663d
child 50785 d1b24f2ceca5
permissions -rw-r--r--
8199712: Flight Recorder Reviewed-by: coleenp, ihse, erikj, dsamersoff, mseledtsov, egahlin, mgronlun Contributed-by: erik.gahlin@oracle.com, markus.gronlund@oracle.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
34666
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents:
diff changeset
     1
/*
49480
d7df2dd501ce 8199809: Don't include frame.inline.hpp and other.inline.hpp from .hpp files
coleenp
parents: 47991
diff changeset
     2
* Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved.
34666
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents:
diff changeset
     3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents:
diff changeset
     4
*
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents:
diff changeset
     5
* This code is free software; you can redistribute it and/or modify it
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents:
diff changeset
     6
* under the terms of the GNU General Public License version 2 only, as
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents:
diff changeset
     7
* published by the Free Software Foundation.
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents:
diff changeset
     8
*
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents:
diff changeset
     9
* This code is distributed in the hope that it will be useful, but WITHOUT
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents:
diff changeset
    10
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents:
diff changeset
    11
* FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents:
diff changeset
    12
* version 2 for more details (a copy is included in the LICENSE file that
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents:
diff changeset
    13
* accompanied this code).
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents:
diff changeset
    14
*
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents:
diff changeset
    15
* You should have received a copy of the GNU General Public License version
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents:
diff changeset
    16
* 2 along with this work; if not, write to the Free Software Foundation,
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents:
diff changeset
    17
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents:
diff changeset
    18
*
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents:
diff changeset
    19
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents:
diff changeset
    20
* or visit www.oracle.com if you need additional information or have any
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents:
diff changeset
    21
* questions.
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents:
diff changeset
    22
*
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents:
diff changeset
    23
*/
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents:
diff changeset
    24
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents:
diff changeset
    25
#include "precompiled.hpp"
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents:
diff changeset
    26
#include "classfile/classFileParser.hpp"
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents:
diff changeset
    27
#include "classfile/classFileStream.hpp"
41182
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents: 40923
diff changeset
    28
#include "classfile/classLoader.hpp"
34666
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents:
diff changeset
    29
#include "classfile/classLoaderData.hpp"
41182
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents: 40923
diff changeset
    30
#include "classfile/classLoaderData.inline.hpp"
34666
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents:
diff changeset
    31
#include "classfile/klassFactory.hpp"
50039
9fec54fe663d 8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents: 49739
diff changeset
    32
#include "memory/filemap.hpp"
41182
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents: 40923
diff changeset
    33
#include "memory/metaspaceShared.hpp"
34666
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents:
diff changeset
    34
#include "memory/resourceArea.hpp"
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents:
diff changeset
    35
#include "prims/jvmtiEnvBase.hpp"
41182
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents: 40923
diff changeset
    36
#include "prims/jvmtiRedefineClasses.hpp"
49480
d7df2dd501ce 8199809: Don't include frame.inline.hpp and other.inline.hpp from .hpp files
coleenp
parents: 47991
diff changeset
    37
#include "runtime/handles.inline.hpp"
50113
caf115bb98ad 8199712: Flight Recorder
egahlin
parents: 50039
diff changeset
    38
#include "utilities/macros.hpp"
caf115bb98ad 8199712: Flight Recorder
egahlin
parents: 50039
diff changeset
    39
#if INCLUDE_JFR
caf115bb98ad 8199712: Flight Recorder
egahlin
parents: 50039
diff changeset
    40
#include "jfr/support/jfrKlassExtension.hpp"
caf115bb98ad 8199712: Flight Recorder
egahlin
parents: 50039
diff changeset
    41
#endif
caf115bb98ad 8199712: Flight Recorder
egahlin
parents: 50039
diff changeset
    42
34666
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents:
diff changeset
    43
41182
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents: 40923
diff changeset
    44
// called during initial loading of a shared class
46329
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 42650
diff changeset
    45
InstanceKlass* KlassFactory::check_shared_class_file_load_hook(
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 42650
diff changeset
    46
                                          InstanceKlass* ik,
41182
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents: 40923
diff changeset
    47
                                          Symbol* class_name,
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents: 40923
diff changeset
    48
                                          Handle class_loader,
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents: 40923
diff changeset
    49
                                          Handle protection_domain, TRAPS) {
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents: 40923
diff changeset
    50
#if INCLUDE_CDS && INCLUDE_JVMTI
46329
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 42650
diff changeset
    51
  assert(ik != NULL, "sanity");
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 42650
diff changeset
    52
  assert(ik->is_shared(), "expecting a shared class");
41182
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents: 40923
diff changeset
    53
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents: 40923
diff changeset
    54
  if (JvmtiExport::should_post_class_file_load_hook()) {
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents: 40923
diff changeset
    55
    assert(THREAD->is_Java_thread(), "must be JavaThread");
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents: 40923
diff changeset
    56
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents: 40923
diff changeset
    57
    // Post the CFLH
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents: 40923
diff changeset
    58
    JvmtiCachedClassFileData* cached_class_file = NULL;
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents: 40923
diff changeset
    59
    JvmtiCachedClassFileData* archived_class_data = ik->get_archived_class_data();
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents: 40923
diff changeset
    60
    assert(archived_class_data != NULL, "shared class has no archived class data");
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents: 40923
diff changeset
    61
    unsigned char* ptr =
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents: 40923
diff changeset
    62
        VM_RedefineClasses::get_cached_class_file_bytes(archived_class_data);
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents: 40923
diff changeset
    63
    unsigned char* end_ptr =
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents: 40923
diff changeset
    64
        ptr + VM_RedefineClasses::get_cached_class_file_len(archived_class_data);
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents: 40923
diff changeset
    65
    unsigned char* old_ptr = ptr;
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents: 40923
diff changeset
    66
    JvmtiExport::post_class_file_load_hook(class_name,
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents: 40923
diff changeset
    67
                                           class_loader,
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents: 40923
diff changeset
    68
                                           protection_domain,
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents: 40923
diff changeset
    69
                                           &ptr,
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents: 40923
diff changeset
    70
                                           &end_ptr,
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents: 40923
diff changeset
    71
                                           &cached_class_file);
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents: 40923
diff changeset
    72
    if (old_ptr != ptr) {
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents: 40923
diff changeset
    73
      // JVMTI agent has modified class file data.
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents: 40923
diff changeset
    74
      // Set new class file stream using JVMTI agent modified class file data.
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents: 40923
diff changeset
    75
      ClassLoaderData* loader_data =
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents: 40923
diff changeset
    76
        ClassLoaderData::class_loader_data(class_loader());
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents: 40923
diff changeset
    77
      int path_index = ik->shared_classpath_index();
47103
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents: 46746
diff changeset
    78
      const char* pathname;
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents: 46746
diff changeset
    79
      if (path_index < 0) {
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents: 46746
diff changeset
    80
        // shared classes loaded by user defined class loader
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents: 46746
diff changeset
    81
        // do not have shared_classpath_index
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents: 46746
diff changeset
    82
        ModuleEntry* mod_entry = ik->module();
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents: 46746
diff changeset
    83
        if (mod_entry != NULL && (mod_entry->location() != NULL)) {
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents: 46746
diff changeset
    84
          ResourceMark rm;
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents: 46746
diff changeset
    85
          pathname = (const char*)(mod_entry->location()->as_C_string());
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents: 46746
diff changeset
    86
        } else {
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents: 46746
diff changeset
    87
          pathname = "";
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents: 46746
diff changeset
    88
        }
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents: 46746
diff changeset
    89
      } else {
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents: 46746
diff changeset
    90
        SharedClassPathEntry* ent =
49739
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents: 49480
diff changeset
    91
          (SharedClassPathEntry*)FileMapInfo::shared_path(path_index);
47103
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents: 46746
diff changeset
    92
        pathname = ent == NULL ? NULL : ent->name();
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents: 46746
diff changeset
    93
      }
41182
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents: 40923
diff changeset
    94
      ClassFileStream* stream = new ClassFileStream(ptr,
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents: 40923
diff changeset
    95
                                                    end_ptr - ptr,
47103
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents: 46746
diff changeset
    96
                                                    pathname,
41182
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents: 40923
diff changeset
    97
                                                    ClassFileStream::verify);
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents: 40923
diff changeset
    98
      ClassFileParser parser(stream,
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents: 40923
diff changeset
    99
                             class_name,
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents: 40923
diff changeset
   100
                             loader_data,
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents: 40923
diff changeset
   101
                             protection_domain,
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents: 40923
diff changeset
   102
                             NULL,
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents: 40923
diff changeset
   103
                             NULL,
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents: 40923
diff changeset
   104
                             ClassFileParser::BROADCAST, // publicity level
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents: 40923
diff changeset
   105
                             CHECK_NULL);
46329
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 42650
diff changeset
   106
      InstanceKlass* new_ik = parser.create_instance_klass(true /* changed_by_loadhook */,
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 42650
diff changeset
   107
                                                           CHECK_NULL);
41182
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents: 40923
diff changeset
   108
      if (cached_class_file != NULL) {
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents: 40923
diff changeset
   109
        new_ik->set_cached_class_file(cached_class_file);
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents: 40923
diff changeset
   110
      }
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents: 40923
diff changeset
   111
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents: 40923
diff changeset
   112
      if (class_loader.is_null()) {
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents: 40923
diff changeset
   113
        ResourceMark rm;
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents: 40923
diff changeset
   114
        ClassLoader::add_package(class_name->as_C_string(), path_index, THREAD);
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents: 40923
diff changeset
   115
      }
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents: 40923
diff changeset
   116
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents: 40923
diff changeset
   117
      return new_ik;
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents: 40923
diff changeset
   118
    }
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents: 40923
diff changeset
   119
  }
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents: 40923
diff changeset
   120
#endif
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents: 40923
diff changeset
   121
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents: 40923
diff changeset
   122
  return NULL;
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents: 40923
diff changeset
   123
}
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents: 40923
diff changeset
   124
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents: 40923
diff changeset
   125
40658
50dd5daad1e6 8163973: VM Anonymous classes should not call Class File Load Hooks
rprotacio
parents: 40016
diff changeset
   126
static ClassFileStream* check_class_file_load_hook(ClassFileStream* stream,
50dd5daad1e6 8163973: VM Anonymous classes should not call Class File Load Hooks
rprotacio
parents: 40016
diff changeset
   127
                                                   Symbol* name,
50dd5daad1e6 8163973: VM Anonymous classes should not call Class File Load Hooks
rprotacio
parents: 40016
diff changeset
   128
                                                   ClassLoaderData* loader_data,
50dd5daad1e6 8163973: VM Anonymous classes should not call Class File Load Hooks
rprotacio
parents: 40016
diff changeset
   129
                                                   Handle protection_domain,
50dd5daad1e6 8163973: VM Anonymous classes should not call Class File Load Hooks
rprotacio
parents: 40016
diff changeset
   130
                                                   JvmtiCachedClassFileData** cached_class_file,
50dd5daad1e6 8163973: VM Anonymous classes should not call Class File Load Hooks
rprotacio
parents: 40016
diff changeset
   131
                                                   TRAPS) {
34666
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents:
diff changeset
   132
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents:
diff changeset
   133
  assert(stream != NULL, "invariant");
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents:
diff changeset
   134
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents:
diff changeset
   135
  if (JvmtiExport::should_post_class_file_load_hook()) {
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents:
diff changeset
   136
    assert(THREAD->is_Java_thread(), "must be a JavaThread");
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents:
diff changeset
   137
    const JavaThread* jt = (JavaThread*)THREAD;
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents:
diff changeset
   138
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents:
diff changeset
   139
    Handle class_loader(THREAD, loader_data->class_loader());
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents:
diff changeset
   140
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents:
diff changeset
   141
    // Get the cached class file bytes (if any) from the class that
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents:
diff changeset
   142
    // is being redefined or retransformed. We use jvmti_thread_state()
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents:
diff changeset
   143
    // instead of JvmtiThreadState::state_for(jt) so we don't allocate
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents:
diff changeset
   144
    // a JvmtiThreadState any earlier than necessary. This will help
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents:
diff changeset
   145
    // avoid the bug described by 7126851.
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents:
diff changeset
   146
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents:
diff changeset
   147
    JvmtiThreadState* state = jt->jvmti_thread_state();
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents:
diff changeset
   148
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents:
diff changeset
   149
    if (state != NULL) {
46329
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 42650
diff changeset
   150
      Klass* k = state->get_class_being_redefined();
34666
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents:
diff changeset
   151
46329
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 42650
diff changeset
   152
      if (k != NULL) {
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 42650
diff changeset
   153
        InstanceKlass* class_being_redefined = InstanceKlass::cast(k);
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 42650
diff changeset
   154
        *cached_class_file = class_being_redefined->get_cached_class_file();
34666
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents:
diff changeset
   155
      }
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents:
diff changeset
   156
    }
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents:
diff changeset
   157
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents:
diff changeset
   158
    unsigned char* ptr = const_cast<unsigned char*>(stream->buffer());
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents:
diff changeset
   159
    unsigned char* end_ptr = ptr + stream->length();
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents:
diff changeset
   160
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents:
diff changeset
   161
    JvmtiExport::post_class_file_load_hook(name,
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents:
diff changeset
   162
                                           class_loader,
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents:
diff changeset
   163
                                           protection_domain,
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents:
diff changeset
   164
                                           &ptr,
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents:
diff changeset
   165
                                           &end_ptr,
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents:
diff changeset
   166
                                           cached_class_file);
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents:
diff changeset
   167
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents:
diff changeset
   168
    if (ptr != stream->buffer()) {
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents:
diff changeset
   169
      // JVMTI agent has modified class file data.
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents:
diff changeset
   170
      // Set new class file stream using JVMTI agent modified class file data.
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents:
diff changeset
   171
      stream = new ClassFileStream(ptr,
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents:
diff changeset
   172
                                   end_ptr - ptr,
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents:
diff changeset
   173
                                   stream->source(),
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents:
diff changeset
   174
                                   stream->need_verify());
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents:
diff changeset
   175
    }
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents:
diff changeset
   176
  }
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents:
diff changeset
   177
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents:
diff changeset
   178
  return stream;
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents:
diff changeset
   179
}
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents:
diff changeset
   180
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents:
diff changeset
   181
46329
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 42650
diff changeset
   182
InstanceKlass* KlassFactory::create_from_stream(ClassFileStream* stream,
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 42650
diff changeset
   183
                                                Symbol* name,
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 42650
diff changeset
   184
                                                ClassLoaderData* loader_data,
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 42650
diff changeset
   185
                                                Handle protection_domain,
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 42650
diff changeset
   186
                                                const InstanceKlass* host_klass,
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 42650
diff changeset
   187
                                                GrowableArray<Handle>* cp_patches,
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 42650
diff changeset
   188
                                                TRAPS) {
34666
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents:
diff changeset
   189
  assert(stream != NULL, "invariant");
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents:
diff changeset
   190
  assert(loader_data != NULL, "invariant");
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents:
diff changeset
   191
  assert(THREAD->is_Java_thread(), "must be a JavaThread");
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents:
diff changeset
   192
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents:
diff changeset
   193
  ResourceMark rm;
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents:
diff changeset
   194
  HandleMark hm;
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents:
diff changeset
   195
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents:
diff changeset
   196
  JvmtiCachedClassFileData* cached_class_file = NULL;
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents:
diff changeset
   197
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents: 36386
diff changeset
   198
  ClassFileStream* old_stream = stream;
5f9eee6b383b 8142968: Module System implementation
alanb
parents: 36386
diff changeset
   199
40658
50dd5daad1e6 8163973: VM Anonymous classes should not call Class File Load Hooks
rprotacio
parents: 40016
diff changeset
   200
  // Skip this processing for VM anonymous classes
50dd5daad1e6 8163973: VM Anonymous classes should not call Class File Load Hooks
rprotacio
parents: 40016
diff changeset
   201
  if (host_klass == NULL) {
50dd5daad1e6 8163973: VM Anonymous classes should not call Class File Load Hooks
rprotacio
parents: 40016
diff changeset
   202
    stream = check_class_file_load_hook(stream,
50dd5daad1e6 8163973: VM Anonymous classes should not call Class File Load Hooks
rprotacio
parents: 40016
diff changeset
   203
                                        name,
50dd5daad1e6 8163973: VM Anonymous classes should not call Class File Load Hooks
rprotacio
parents: 40016
diff changeset
   204
                                        loader_data,
50dd5daad1e6 8163973: VM Anonymous classes should not call Class File Load Hooks
rprotacio
parents: 40016
diff changeset
   205
                                        protection_domain,
50dd5daad1e6 8163973: VM Anonymous classes should not call Class File Load Hooks
rprotacio
parents: 40016
diff changeset
   206
                                        &cached_class_file,
50dd5daad1e6 8163973: VM Anonymous classes should not call Class File Load Hooks
rprotacio
parents: 40016
diff changeset
   207
                                        CHECK_NULL);
50dd5daad1e6 8163973: VM Anonymous classes should not call Class File Load Hooks
rprotacio
parents: 40016
diff changeset
   208
  }
34666
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents:
diff changeset
   209
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents:
diff changeset
   210
  ClassFileParser parser(stream,
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents:
diff changeset
   211
                         name,
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents:
diff changeset
   212
                         loader_data,
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents:
diff changeset
   213
                         protection_domain,
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents:
diff changeset
   214
                         host_klass,
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents:
diff changeset
   215
                         cp_patches,
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents:
diff changeset
   216
                         ClassFileParser::BROADCAST, // publicity level
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents:
diff changeset
   217
                         CHECK_NULL);
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents:
diff changeset
   218
46329
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 42650
diff changeset
   219
  InstanceKlass* result = parser.create_instance_klass(old_stream != stream, CHECK_NULL);
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents: 36386
diff changeset
   220
  assert(result == parser.create_instance_klass(old_stream != stream, THREAD), "invariant");
34666
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents:
diff changeset
   221
46329
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 42650
diff changeset
   222
  if (result == NULL) {
34666
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents:
diff changeset
   223
    return NULL;
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents:
diff changeset
   224
  }
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents:
diff changeset
   225
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents:
diff changeset
   226
  if (cached_class_file != NULL) {
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents:
diff changeset
   227
    // JVMTI: we have an InstanceKlass now, tell it about the cached bytes
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents:
diff changeset
   228
    result->set_cached_class_file(cached_class_file);
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents:
diff changeset
   229
  }
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents:
diff changeset
   230
47668
fc4cfca10556 8132547: [AOT] support invokedynamic instructions
dlong
parents: 47216
diff changeset
   231
  if (result->should_store_fingerprint()) {
fc4cfca10556 8132547: [AOT] support invokedynamic instructions
dlong
parents: 47216
diff changeset
   232
    result->store_fingerprint(stream->compute_fingerprint());
42650
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 41739
diff changeset
   233
  }
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 41739
diff changeset
   234
50113
caf115bb98ad 8199712: Flight Recorder
egahlin
parents: 50039
diff changeset
   235
  JFR_ONLY(ON_KLASS_CREATION(result, parser, THREAD);)
36386
d7f5e6df26df 8147442: Event-based tracing to allow for tracing Klass creation
mgronlun
parents: 34666
diff changeset
   236
47103
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents: 46746
diff changeset
   237
#if INCLUDE_CDS
41182
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents: 40923
diff changeset
   238
  if (DumpSharedSpaces) {
49739
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents: 49480
diff changeset
   239
    ClassLoader::record_result(result, stream, THREAD);
47103
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents: 46746
diff changeset
   240
#if INCLUDE_JVMTI
41182
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents: 40923
diff changeset
   241
    assert(cached_class_file == NULL, "Sanity");
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents: 40923
diff changeset
   242
    // Archive the class stream data into the optional data section
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents: 40923
diff changeset
   243
    JvmtiCachedClassFileData *p;
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents: 40923
diff changeset
   244
    int len;
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents: 40923
diff changeset
   245
    const unsigned char *bytes;
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents: 40923
diff changeset
   246
    // event based tracing might set cached_class_file
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents: 40923
diff changeset
   247
    if ((bytes = result->get_cached_class_file_bytes()) != NULL) {
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents: 40923
diff changeset
   248
      len = result->get_cached_class_file_len();
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents: 40923
diff changeset
   249
    } else {
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents: 40923
diff changeset
   250
      len = stream->length();
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents: 40923
diff changeset
   251
      bytes = stream->buffer();
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents: 40923
diff changeset
   252
    }
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46329
diff changeset
   253
    p = (JvmtiCachedClassFileData*)os::malloc(offset_of(JvmtiCachedClassFileData, data) + len, mtInternal);
41182
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents: 40923
diff changeset
   254
    p->length = len;
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents: 40923
diff changeset
   255
    memcpy(p->data, bytes, len);
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents: 40923
diff changeset
   256
    result->set_archived_class_data(p);
47103
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents: 46746
diff changeset
   257
#endif // INCLUDE_JVMTI
41182
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents: 40923
diff changeset
   258
  }
47103
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents: 46746
diff changeset
   259
#endif // INCLUDE_CDS
41182
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents: 40923
diff changeset
   260
34666
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents:
diff changeset
   261
  return result;
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents:
diff changeset
   262
}