hotspot/src/share/vm/classfile/klassFactory.cpp
author kvn
Sun, 11 Dec 2016 19:07:04 -0800
changeset 42650 1f304d0c888b
parent 41739 4a4b9f6a4306
child 46329 53ccc37bda19
permissions -rw-r--r--
8171008: Integrate AOT compiler into JDK Reviewed-by: erikj, mchung, psandoz, coleenp, iklam, stefank, simonis Contributed-by: Bharadwaj Yadavalli <bharadwaj.yadavalli@oracle.com>, Christian Thalinger <cthalinger@twitter.com>, Dean Long <dean.long@oracle.com>, Dmitrij Pochepko <dmitrij.pochepko@oracle.com>, Dmitry Chuyko <dmitry.chuyko@oracle.com>, Doug Simon <doug.simon@oracle.com>, Eric Caspole <eric.caspole@oracle.com>, Igor Ignatyev <igor.ignatyev@oracle.com>, Igor Veresov <igor.veresov@oracle.com>, John Rose <john.r.rose@oracle.com>, Morris Meyer <morris.meyer@oracle.com>, Niclas Adlertz <niclas.adlertz@oracle.com>, Rickard Backman <rickard.backman@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
/*
36386
d7f5e6df26df 8147442: Event-based tracing to allow for tracing Klass creation
mgronlun
parents: 34666
diff changeset
     2
* Copyright (c) 2015, 2016, 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"
41182
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents: 40923
diff changeset
    32
#include "classfile/sharedClassUtil.hpp"
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"
36386
d7f5e6df26df 8147442: Event-based tracing to allow for tracing Klass creation
mgronlun
parents: 34666
diff changeset
    37
#include "trace/traceMacros.hpp"
34666
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents:
diff changeset
    38
41182
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents: 40923
diff changeset
    39
// called during initial loading of a shared class
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents: 40923
diff changeset
    40
instanceKlassHandle KlassFactory::check_shared_class_file_load_hook(
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents: 40923
diff changeset
    41
                                          instanceKlassHandle ik,
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents: 40923
diff changeset
    42
                                          Symbol* class_name,
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents: 40923
diff changeset
    43
                                          Handle class_loader,
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents: 40923
diff changeset
    44
                                          Handle protection_domain, TRAPS) {
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents: 40923
diff changeset
    45
#if INCLUDE_CDS && INCLUDE_JVMTI
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents: 40923
diff changeset
    46
  assert(ik.not_null(), "sanity");
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents: 40923
diff changeset
    47
  assert(ik()->is_shared(), "expecting a shared class");
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents: 40923
diff changeset
    48
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents: 40923
diff changeset
    49
  if (JvmtiExport::should_post_class_file_load_hook()) {
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents: 40923
diff changeset
    50
    assert(THREAD->is_Java_thread(), "must be JavaThread");
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents: 40923
diff changeset
    51
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents: 40923
diff changeset
    52
    // Post the CFLH
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents: 40923
diff changeset
    53
    JvmtiCachedClassFileData* cached_class_file = NULL;
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents: 40923
diff changeset
    54
    JvmtiCachedClassFileData* archived_class_data = ik->get_archived_class_data();
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents: 40923
diff changeset
    55
    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
    56
    unsigned char* ptr =
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents: 40923
diff changeset
    57
        VM_RedefineClasses::get_cached_class_file_bytes(archived_class_data);
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents: 40923
diff changeset
    58
    unsigned char* end_ptr =
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents: 40923
diff changeset
    59
        ptr + VM_RedefineClasses::get_cached_class_file_len(archived_class_data);
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents: 40923
diff changeset
    60
    unsigned char* old_ptr = ptr;
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents: 40923
diff changeset
    61
    JvmtiExport::post_class_file_load_hook(class_name,
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents: 40923
diff changeset
    62
                                           class_loader,
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents: 40923
diff changeset
    63
                                           protection_domain,
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents: 40923
diff changeset
    64
                                           &ptr,
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents: 40923
diff changeset
    65
                                           &end_ptr,
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents: 40923
diff changeset
    66
                                           &cached_class_file);
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents: 40923
diff changeset
    67
    if (old_ptr != ptr) {
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents: 40923
diff changeset
    68
      // JVMTI agent has modified class file data.
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents: 40923
diff changeset
    69
      // 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
    70
      ClassLoaderData* loader_data =
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents: 40923
diff changeset
    71
        ClassLoaderData::class_loader_data(class_loader());
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents: 40923
diff changeset
    72
      int path_index = ik->shared_classpath_index();
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents: 40923
diff changeset
    73
      SharedClassPathEntry* ent =
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents: 40923
diff changeset
    74
        (SharedClassPathEntry*)FileMapInfo::shared_classpath(path_index);
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents: 40923
diff changeset
    75
      ClassFileStream* stream = new ClassFileStream(ptr,
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents: 40923
diff changeset
    76
                                                    end_ptr - ptr,
41739
4a4b9f6a4306 8167333: Invalid source path info might be used when creating ClassFileStream after CFLH transforms a shared classes in some cases
jiangli
parents: 41182
diff changeset
    77
                                                    ent == NULL ? NULL : ent->_name,
41182
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents: 40923
diff changeset
    78
                                                    ClassFileStream::verify);
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents: 40923
diff changeset
    79
      ClassFileParser parser(stream,
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents: 40923
diff changeset
    80
                             class_name,
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents: 40923
diff changeset
    81
                             loader_data,
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents: 40923
diff changeset
    82
                             protection_domain,
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents: 40923
diff changeset
    83
                             NULL,
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents: 40923
diff changeset
    84
                             NULL,
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents: 40923
diff changeset
    85
                             ClassFileParser::BROADCAST, // publicity level
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents: 40923
diff changeset
    86
                             CHECK_NULL);
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents: 40923
diff changeset
    87
      instanceKlassHandle new_ik = parser.create_instance_klass(true /* changed_by_loadhook */,
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents: 40923
diff changeset
    88
                                                                CHECK_NULL);
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents: 40923
diff changeset
    89
      if (cached_class_file != NULL) {
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents: 40923
diff changeset
    90
        new_ik->set_cached_class_file(cached_class_file);
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents: 40923
diff changeset
    91
      }
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents: 40923
diff changeset
    92
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents: 40923
diff changeset
    93
      if (class_loader.is_null()) {
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents: 40923
diff changeset
    94
        ResourceMark rm;
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents: 40923
diff changeset
    95
        ClassLoader::add_package(class_name->as_C_string(), path_index, THREAD);
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents: 40923
diff changeset
    96
      }
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents: 40923
diff changeset
    97
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents: 40923
diff changeset
    98
      return new_ik;
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents: 40923
diff changeset
    99
    }
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents: 40923
diff changeset
   100
  }
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents: 40923
diff changeset
   101
#endif
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents: 40923
diff changeset
   102
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents: 40923
diff changeset
   103
  return NULL;
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents: 40923
diff changeset
   104
}
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents: 40923
diff changeset
   105
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents: 40923
diff changeset
   106
40658
50dd5daad1e6 8163973: VM Anonymous classes should not call Class File Load Hooks
rprotacio
parents: 40016
diff changeset
   107
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
   108
                                                   Symbol* name,
50dd5daad1e6 8163973: VM Anonymous classes should not call Class File Load Hooks
rprotacio
parents: 40016
diff changeset
   109
                                                   ClassLoaderData* loader_data,
50dd5daad1e6 8163973: VM Anonymous classes should not call Class File Load Hooks
rprotacio
parents: 40016
diff changeset
   110
                                                   Handle protection_domain,
50dd5daad1e6 8163973: VM Anonymous classes should not call Class File Load Hooks
rprotacio
parents: 40016
diff changeset
   111
                                                   JvmtiCachedClassFileData** cached_class_file,
50dd5daad1e6 8163973: VM Anonymous classes should not call Class File Load Hooks
rprotacio
parents: 40016
diff changeset
   112
                                                   TRAPS) {
34666
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents:
diff changeset
   113
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents:
diff changeset
   114
  assert(stream != NULL, "invariant");
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents:
diff changeset
   115
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents:
diff changeset
   116
  if (JvmtiExport::should_post_class_file_load_hook()) {
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents:
diff changeset
   117
    assert(THREAD->is_Java_thread(), "must be a JavaThread");
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents:
diff changeset
   118
    const JavaThread* jt = (JavaThread*)THREAD;
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents:
diff changeset
   119
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents:
diff changeset
   120
    Handle class_loader(THREAD, loader_data->class_loader());
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents:
diff changeset
   121
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents:
diff changeset
   122
    // Get the cached class file bytes (if any) from the class that
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents:
diff changeset
   123
    // is being redefined or retransformed. We use jvmti_thread_state()
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents:
diff changeset
   124
    // instead of JvmtiThreadState::state_for(jt) so we don't allocate
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents:
diff changeset
   125
    // a JvmtiThreadState any earlier than necessary. This will help
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents:
diff changeset
   126
    // avoid the bug described by 7126851.
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents:
diff changeset
   127
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents:
diff changeset
   128
    JvmtiThreadState* state = jt->jvmti_thread_state();
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents:
diff changeset
   129
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents:
diff changeset
   130
    if (state != NULL) {
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents:
diff changeset
   131
      KlassHandle* h_class_being_redefined =
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents:
diff changeset
   132
        state->get_class_being_redefined();
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents:
diff changeset
   133
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents:
diff changeset
   134
      if (h_class_being_redefined != NULL) {
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents:
diff changeset
   135
        instanceKlassHandle ikh_class_being_redefined =
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents:
diff changeset
   136
          instanceKlassHandle(THREAD, (*h_class_being_redefined)());
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents:
diff changeset
   137
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents:
diff changeset
   138
        *cached_class_file = ikh_class_being_redefined->get_cached_class_file();
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents:
diff changeset
   139
      }
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents:
diff changeset
   140
    }
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents:
diff changeset
   141
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents:
diff changeset
   142
    unsigned char* ptr = const_cast<unsigned char*>(stream->buffer());
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents:
diff changeset
   143
    unsigned char* end_ptr = ptr + stream->length();
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents:
diff changeset
   144
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents:
diff changeset
   145
    JvmtiExport::post_class_file_load_hook(name,
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents:
diff changeset
   146
                                           class_loader,
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents:
diff changeset
   147
                                           protection_domain,
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents:
diff changeset
   148
                                           &ptr,
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents:
diff changeset
   149
                                           &end_ptr,
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents:
diff changeset
   150
                                           cached_class_file);
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents:
diff changeset
   151
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents:
diff changeset
   152
    if (ptr != stream->buffer()) {
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents:
diff changeset
   153
      // JVMTI agent has modified class file data.
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents:
diff changeset
   154
      // Set new class file stream using JVMTI agent modified class file data.
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents:
diff changeset
   155
      stream = new ClassFileStream(ptr,
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents:
diff changeset
   156
                                   end_ptr - ptr,
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents:
diff changeset
   157
                                   stream->source(),
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents:
diff changeset
   158
                                   stream->need_verify());
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents:
diff changeset
   159
    }
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents:
diff changeset
   160
  }
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents:
diff changeset
   161
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents:
diff changeset
   162
  return stream;
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents:
diff changeset
   163
}
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents:
diff changeset
   164
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents:
diff changeset
   165
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents:
diff changeset
   166
instanceKlassHandle KlassFactory::create_from_stream(ClassFileStream* stream,
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents:
diff changeset
   167
                                                     Symbol* name,
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents:
diff changeset
   168
                                                     ClassLoaderData* loader_data,
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents:
diff changeset
   169
                                                     Handle protection_domain,
40923
10fe1c28b9f6 8058575: IllegalAccessError trying to access package-private class from VM anonymous class
hseigel
parents: 40658
diff changeset
   170
                                                     const InstanceKlass* host_klass,
34666
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents:
diff changeset
   171
                                                     GrowableArray<Handle>* cp_patches,
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents:
diff changeset
   172
                                                     TRAPS) {
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents:
diff changeset
   173
  assert(stream != NULL, "invariant");
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents:
diff changeset
   174
  assert(loader_data != NULL, "invariant");
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents:
diff changeset
   175
  assert(THREAD->is_Java_thread(), "must be a JavaThread");
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents:
diff changeset
   176
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents:
diff changeset
   177
  ResourceMark rm;
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents:
diff changeset
   178
  HandleMark hm;
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents:
diff changeset
   179
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents:
diff changeset
   180
  JvmtiCachedClassFileData* cached_class_file = NULL;
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents:
diff changeset
   181
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents: 36386
diff changeset
   182
  ClassFileStream* old_stream = stream;
5f9eee6b383b 8142968: Module System implementation
alanb
parents: 36386
diff changeset
   183
40658
50dd5daad1e6 8163973: VM Anonymous classes should not call Class File Load Hooks
rprotacio
parents: 40016
diff changeset
   184
  // Skip this processing for VM anonymous classes
50dd5daad1e6 8163973: VM Anonymous classes should not call Class File Load Hooks
rprotacio
parents: 40016
diff changeset
   185
  if (host_klass == NULL) {
50dd5daad1e6 8163973: VM Anonymous classes should not call Class File Load Hooks
rprotacio
parents: 40016
diff changeset
   186
    stream = check_class_file_load_hook(stream,
50dd5daad1e6 8163973: VM Anonymous classes should not call Class File Load Hooks
rprotacio
parents: 40016
diff changeset
   187
                                        name,
50dd5daad1e6 8163973: VM Anonymous classes should not call Class File Load Hooks
rprotacio
parents: 40016
diff changeset
   188
                                        loader_data,
50dd5daad1e6 8163973: VM Anonymous classes should not call Class File Load Hooks
rprotacio
parents: 40016
diff changeset
   189
                                        protection_domain,
50dd5daad1e6 8163973: VM Anonymous classes should not call Class File Load Hooks
rprotacio
parents: 40016
diff changeset
   190
                                        &cached_class_file,
50dd5daad1e6 8163973: VM Anonymous classes should not call Class File Load Hooks
rprotacio
parents: 40016
diff changeset
   191
                                        CHECK_NULL);
50dd5daad1e6 8163973: VM Anonymous classes should not call Class File Load Hooks
rprotacio
parents: 40016
diff changeset
   192
  }
34666
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents:
diff changeset
   193
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents:
diff changeset
   194
  ClassFileParser parser(stream,
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents:
diff changeset
   195
                         name,
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents:
diff changeset
   196
                         loader_data,
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents:
diff changeset
   197
                         protection_domain,
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents:
diff changeset
   198
                         host_klass,
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents:
diff changeset
   199
                         cp_patches,
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents:
diff changeset
   200
                         ClassFileParser::BROADCAST, // publicity level
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents:
diff changeset
   201
                         CHECK_NULL);
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents:
diff changeset
   202
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents: 36386
diff changeset
   203
  instanceKlassHandle result = parser.create_instance_klass(old_stream != stream, CHECK_NULL);
5f9eee6b383b 8142968: Module System implementation
alanb
parents: 36386
diff changeset
   204
  assert(result == parser.create_instance_klass(old_stream != stream, THREAD), "invariant");
34666
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents:
diff changeset
   205
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents:
diff changeset
   206
  if (result.is_null()) {
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents:
diff changeset
   207
    return NULL;
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents:
diff changeset
   208
  }
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents:
diff changeset
   209
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents:
diff changeset
   210
  if (cached_class_file != NULL) {
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents:
diff changeset
   211
    // JVMTI: we have an InstanceKlass now, tell it about the cached bytes
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents:
diff changeset
   212
    result->set_cached_class_file(cached_class_file);
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents:
diff changeset
   213
  }
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents:
diff changeset
   214
42650
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 41739
diff changeset
   215
  if (InstanceKlass::should_store_fingerprint()) {
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 41739
diff changeset
   216
    result->store_fingerprint(!result->is_anonymous() ? stream->compute_fingerprint() : 0);
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 41739
diff changeset
   217
  }
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 41739
diff changeset
   218
36386
d7f5e6df26df 8147442: Event-based tracing to allow for tracing Klass creation
mgronlun
parents: 34666
diff changeset
   219
  TRACE_KLASS_CREATION(result, parser, THREAD);
d7f5e6df26df 8147442: Event-based tracing to allow for tracing Klass creation
mgronlun
parents: 34666
diff changeset
   220
41182
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents: 40923
diff changeset
   221
#if INCLUDE_CDS && INCLUDE_JVMTI
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents: 40923
diff changeset
   222
  if (DumpSharedSpaces) {
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents: 40923
diff changeset
   223
    assert(cached_class_file == NULL, "Sanity");
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents: 40923
diff changeset
   224
    // Archive the class stream data into the optional data section
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents: 40923
diff changeset
   225
    JvmtiCachedClassFileData *p;
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents: 40923
diff changeset
   226
    int len;
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents: 40923
diff changeset
   227
    const unsigned char *bytes;
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents: 40923
diff changeset
   228
    // event based tracing might set cached_class_file
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents: 40923
diff changeset
   229
    if ((bytes = result->get_cached_class_file_bytes()) != NULL) {
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents: 40923
diff changeset
   230
      len = result->get_cached_class_file_len();
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents: 40923
diff changeset
   231
    } else {
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents: 40923
diff changeset
   232
      len = stream->length();
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents: 40923
diff changeset
   233
      bytes = stream->buffer();
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents: 40923
diff changeset
   234
    }
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents: 40923
diff changeset
   235
    p = (JvmtiCachedClassFileData*)MetaspaceShared::optional_data_space_alloc(
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents: 40923
diff changeset
   236
                    offset_of(JvmtiCachedClassFileData, data) + len);
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents: 40923
diff changeset
   237
    p->length = len;
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents: 40923
diff changeset
   238
    memcpy(p->data, bytes, len);
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents: 40923
diff changeset
   239
    result->set_archived_class_data(p);
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents: 40923
diff changeset
   240
  }
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents: 40923
diff changeset
   241
#endif
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents: 40923
diff changeset
   242
34666
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents:
diff changeset
   243
  return result;
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents:
diff changeset
   244
}