src/hotspot/share/classfile/classLoaderExt.cpp
author coleenp
Wed, 13 Nov 2019 08:23:23 -0500
changeset 59056 15936b142f86
parent 58447 319173c62caa
child 58679 9c3209ff7550
permissions -rw-r--r--
8233913: Remove implicit conversion from Method* to methodHandle Summary: Fix call sites to use existing THREAD local or pass down THREAD local for shallower callsites. Make linkResolver methods return Method* for caller to handleize if needed. Reviewed-by: iklam, thartmann, hseigel
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
34257
4be3504cc03b 8140802: Clean up and refactor of class loading code for CDS
iklam
parents:
diff changeset
     1
/*
53882
ca682d9d8db5 8214777: Avoid some GCC 8.X strncpy() errors in HotSpot
mikael
parents: 52631
diff changeset
     2
 * Copyright (c) 2015, 2019, Oracle and/or its affiliates. All rights reserved.
34257
4be3504cc03b 8140802: Clean up and refactor of class loading code for CDS
iklam
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4be3504cc03b 8140802: Clean up and refactor of class loading code for CDS
iklam
parents:
diff changeset
     4
 *
4be3504cc03b 8140802: Clean up and refactor of class loading code for CDS
iklam
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
4be3504cc03b 8140802: Clean up and refactor of class loading code for CDS
iklam
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
4be3504cc03b 8140802: Clean up and refactor of class loading code for CDS
iklam
parents:
diff changeset
     7
 * published by the Free Software Foundation.
4be3504cc03b 8140802: Clean up and refactor of class loading code for CDS
iklam
parents:
diff changeset
     8
 *
4be3504cc03b 8140802: Clean up and refactor of class loading code for CDS
iklam
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
4be3504cc03b 8140802: Clean up and refactor of class loading code for CDS
iklam
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
4be3504cc03b 8140802: Clean up and refactor of class loading code for CDS
iklam
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
4be3504cc03b 8140802: Clean up and refactor of class loading code for CDS
iklam
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
4be3504cc03b 8140802: Clean up and refactor of class loading code for CDS
iklam
parents:
diff changeset
    13
 * accompanied this code).
4be3504cc03b 8140802: Clean up and refactor of class loading code for CDS
iklam
parents:
diff changeset
    14
 *
4be3504cc03b 8140802: Clean up and refactor of class loading code for CDS
iklam
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
4be3504cc03b 8140802: Clean up and refactor of class loading code for CDS
iklam
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
4be3504cc03b 8140802: Clean up and refactor of class loading code for CDS
iklam
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
4be3504cc03b 8140802: Clean up and refactor of class loading code for CDS
iklam
parents:
diff changeset
    18
 *
4be3504cc03b 8140802: Clean up and refactor of class loading code for CDS
iklam
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
4be3504cc03b 8140802: Clean up and refactor of class loading code for CDS
iklam
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
4be3504cc03b 8140802: Clean up and refactor of class loading code for CDS
iklam
parents:
diff changeset
    21
 * questions.
4be3504cc03b 8140802: Clean up and refactor of class loading code for CDS
iklam
parents:
diff changeset
    22
 *
4be3504cc03b 8140802: Clean up and refactor of class loading code for CDS
iklam
parents:
diff changeset
    23
 */
4be3504cc03b 8140802: Clean up and refactor of class loading code for CDS
iklam
parents:
diff changeset
    24
4be3504cc03b 8140802: Clean up and refactor of class loading code for CDS
iklam
parents:
diff changeset
    25
#include "precompiled.hpp"
48138
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
    26
#include "classfile/classFileParser.hpp"
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
    27
#include "classfile/classFileStream.hpp"
49340
4e82736053ae 8191102: Incorrect include file use in classLoader.hpp
hseigel
parents: 48138
diff changeset
    28
#include "classfile/classLoader.inline.hpp"
34257
4be3504cc03b 8140802: Clean up and refactor of class loading code for CDS
iklam
parents:
diff changeset
    29
#include "classfile/classLoaderExt.hpp"
48138
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
    30
#include "classfile/classLoaderData.inline.hpp"
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
    31
#include "classfile/klassFactory.hpp"
49739
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents: 49341
diff changeset
    32
#include "classfile/modules.hpp"
48138
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
    33
#include "classfile/systemDictionaryShared.hpp"
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
    34
#include "classfile/vmSymbols.hpp"
58110
85e1de070bef 8186988: use log_warning() and log_error() instead of tty->print_cr for CDS warning and error messages
ccheung
parents: 58096
diff changeset
    35
#include "logging/log.hpp"
48138
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
    36
#include "memory/allocation.inline.hpp"
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
    37
#include "memory/filemap.hpp"
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
    38
#include "memory/resourceArea.hpp"
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
    39
#include "oops/instanceKlass.hpp"
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
    40
#include "oops/oop.inline.hpp"
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
    41
#include "oops/symbol.hpp"
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
    42
#include "runtime/arguments.hpp"
49739
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents: 49341
diff changeset
    43
#include "runtime/handles.inline.hpp"
48138
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
    44
#include "runtime/java.hpp"
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
    45
#include "runtime/javaCalls.hpp"
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
    46
#include "runtime/os.hpp"
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
    47
#include "services/threadService.hpp"
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
    48
#include "utilities/stringUtils.hpp"
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
    49
49739
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents: 49341
diff changeset
    50
jshort ClassLoaderExt::_app_class_paths_start_index = ClassLoaderExt::max_classpath_index;
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents: 49341
diff changeset
    51
jshort ClassLoaderExt::_app_module_paths_start_index = ClassLoaderExt::max_classpath_index;
51439
0517bd2a0eda 8209385: CDS runtime classpath checking is too strict when only classes from the system modules are archived
ccheung
parents: 50329
diff changeset
    52
jshort ClassLoaderExt::_max_used_path_index = 0;
48138
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
    53
bool ClassLoaderExt::_has_app_classes = false;
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
    54
bool ClassLoaderExt::_has_platform_classes = false;
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
    55
49931
840e26123940 8193213: Make the UseAppCDS option obsolete.
jiangli
parents: 49739
diff changeset
    56
void ClassLoaderExt::append_boot_classpath(ClassPathEntry* new_entry) {
50329
18fba780c1d1 8203031: segfaults from jvmti_AddToBootstrapClassLoaderSearch
amenkov
parents: 50079
diff changeset
    57
  if (UseSharedSpaces) {
18fba780c1d1 8203031: segfaults from jvmti_AddToBootstrapClassLoaderSearch
amenkov
parents: 50079
diff changeset
    58
    warning("Sharing is only supported for boot loader classes because bootstrap classpath has been appended");
58096
0d97bf7cf8a4 8230586: Encapsulate fields in filemap.hpp
iklam
parents: 57898
diff changeset
    59
    FileMapInfo::current_info()->set_has_platform_or_app_classes(false);
50329
18fba780c1d1 8203031: segfaults from jvmti_AddToBootstrapClassLoaderSearch
amenkov
parents: 50079
diff changeset
    60
  }
49931
840e26123940 8193213: Make the UseAppCDS option obsolete.
jiangli
parents: 49739
diff changeset
    61
  ClassLoader::add_to_boot_append_entries(new_entry);
840e26123940 8193213: Make the UseAppCDS option obsolete.
jiangli
parents: 49739
diff changeset
    62
}
840e26123940 8193213: Make the UseAppCDS option obsolete.
jiangli
parents: 49739
diff changeset
    63
48138
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
    64
void ClassLoaderExt::setup_app_search_path() {
58447
319173c62caa 8231606: _method_ordering is not set during CDS dynamic dump time
ccheung
parents: 58110
diff changeset
    65
  Arguments::assert_is_dumping_archive();
49739
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents: 49341
diff changeset
    66
  _app_class_paths_start_index = ClassLoader::num_boot_classpath_entries();
48138
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
    67
  char* app_class_path = os::strdup(Arguments::get_appclasspath());
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
    68
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
    69
  if (strcmp(app_class_path, ".") == 0) {
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
    70
    // This doesn't make any sense, even for AppCDS, so let's skip it. We
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
    71
    // don't want to throw an error here because -cp "." is usually assigned
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
    72
    // by the launcher when classpath is not specified.
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
    73
    trace_class_path("app loader class path (skipped)=", app_class_path);
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
    74
  } else {
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
    75
    trace_class_path("app loader class path=", app_class_path);
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
    76
    ClassLoader::setup_app_search_path(app_class_path);
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
    77
  }
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
    78
}
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
    79
49739
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents: 49341
diff changeset
    80
void ClassLoaderExt::process_module_table(ModuleEntryTable* met, TRAPS) {
50079
5830a17d9fc8 8202289: Non-empty directory in module path is not handled properly at CDS/AppCDS dump time
ccheung
parents: 50039
diff changeset
    81
  ResourceMark rm(THREAD);
49739
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents: 49341
diff changeset
    82
  for (int i = 0; i < met->table_size(); i++) {
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents: 49341
diff changeset
    83
    for (ModuleEntry* m = met->bucket(i); m != NULL;) {
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents: 49341
diff changeset
    84
      char* path = m->location()->as_C_string();
50079
5830a17d9fc8 8202289: Non-empty directory in module path is not handled properly at CDS/AppCDS dump time
ccheung
parents: 50039
diff changeset
    85
      if (strncmp(path, "file:", 5) == 0) {
49739
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents: 49341
diff changeset
    86
        path = ClassLoader::skip_uri_protocol(path);
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents: 49341
diff changeset
    87
        ClassLoader::setup_module_search_path(path, THREAD);
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents: 49341
diff changeset
    88
      }
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents: 49341
diff changeset
    89
      m = m->next();
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents: 49341
diff changeset
    90
    }
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents: 49341
diff changeset
    91
  }
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents: 49341
diff changeset
    92
}
49931
840e26123940 8193213: Make the UseAppCDS option obsolete.
jiangli
parents: 49739
diff changeset
    93
void ClassLoaderExt::setup_module_paths(TRAPS) {
58447
319173c62caa 8231606: _method_ordering is not set during CDS dynamic dump time
ccheung
parents: 58110
diff changeset
    94
  Arguments::assert_is_dumping_archive();
49739
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents: 49341
diff changeset
    95
  _app_module_paths_start_index = ClassLoader::num_boot_classpath_entries() +
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents: 49341
diff changeset
    96
                              ClassLoader::num_app_classpath_entries();
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents: 49341
diff changeset
    97
  Handle system_class_loader (THREAD, SystemDictionary::java_system_loader());
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents: 49341
diff changeset
    98
  ModuleEntryTable* met = Modules::get_module_entry_table(system_class_loader);
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents: 49341
diff changeset
    99
  process_module_table(met, THREAD);
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents: 49341
diff changeset
   100
}
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents: 49341
diff changeset
   101
48138
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
   102
char* ClassLoaderExt::read_manifest(ClassPathEntry* entry, jint *manifest_size, bool clean_text, TRAPS) {
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
   103
  const char* name = "META-INF/MANIFEST.MF";
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
   104
  char* manifest;
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
   105
  jint size;
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
   106
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
   107
  assert(entry->is_jar_file(), "must be");
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
   108
  manifest = (char*) ((ClassPathZipEntry*)entry )->open_entry(name, &size, true, CHECK_NULL);
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
   109
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
   110
  if (manifest == NULL) { // No Manifest
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
   111
    *manifest_size = 0;
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
   112
    return NULL;
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
   113
  }
34257
4be3504cc03b 8140802: Clean up and refactor of class loading code for CDS
iklam
parents:
diff changeset
   114
4be3504cc03b 8140802: Clean up and refactor of class loading code for CDS
iklam
parents:
diff changeset
   115
48138
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
   116
  if (clean_text) {
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
   117
    // See http://docs.oracle.com/javase/6/docs/technotes/guides/jar/jar.html#JAR%20Manifest
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
   118
    // (1): replace all CR/LF and CR with LF
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
   119
    StringUtils::replace_no_expand(manifest, "\r\n", "\n");
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
   120
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
   121
    // (2) remove all new-line continuation (remove all "\n " substrings)
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
   122
    StringUtils::replace_no_expand(manifest, "\n ", "");
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
   123
  }
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
   124
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
   125
  *manifest_size = (jint)strlen(manifest);
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
   126
  return manifest;
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
   127
}
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
   128
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
   129
char* ClassLoaderExt::get_class_path_attr(const char* jar_path, char* manifest, jint manifest_size) {
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
   130
  const char* tag = "Class-Path: ";
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
   131
  const int tag_len = (int)strlen(tag);
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
   132
  char* found = NULL;
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
   133
  char* line_start = manifest;
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
   134
  char* end = manifest + manifest_size;
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
   135
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
   136
  assert(*end == 0, "must be nul-terminated");
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
   137
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
   138
  while (line_start < end) {
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
   139
    char* line_end = strchr(line_start, '\n');
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
   140
    if (line_end == NULL) {
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
   141
      // JAR spec require the manifest file to be terminated by a new line.
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
   142
      break;
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
   143
    }
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
   144
    if (strncmp(tag, line_start, tag_len) == 0) {
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
   145
      if (found != NULL) {
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
   146
        // Same behavior as jdk/src/share/classes/java/util/jar/Attributes.java
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
   147
        // If duplicated entries are found, the last one is used.
58110
85e1de070bef 8186988: use log_warning() and log_error() instead of tty->print_cr for CDS warning and error messages
ccheung
parents: 58096
diff changeset
   148
        log_warning(cds)("Warning: Duplicate name in Manifest: %s.\n"
48138
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
   149
                      "Ensure that the manifest does not have duplicate entries, and\n"
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
   150
                      "that blank lines separate individual sections in both your\n"
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
   151
                      "manifest and in the META-INF/MANIFEST.MF entry in the jar file:\n%s\n", tag, jar_path);
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
   152
      }
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
   153
      found = line_start + tag_len;
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
   154
      assert(found <= line_end, "sanity");
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
   155
      *line_end = '\0';
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
   156
    }
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
   157
    line_start = line_end + 1;
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
   158
  }
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
   159
  return found;
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
   160
}
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
   161
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
   162
void ClassLoaderExt::process_jar_manifest(ClassPathEntry* entry,
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
   163
                                          bool check_for_duplicates) {
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
   164
  Thread* THREAD = Thread::current();
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
   165
  ResourceMark rm(THREAD);
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
   166
  jint manifest_size;
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
   167
  char* manifest = read_manifest(entry, &manifest_size, CHECK);
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
   168
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
   169
  if (manifest == NULL) {
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
   170
    return;
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
   171
  }
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
   172
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
   173
  if (strstr(manifest, "Extension-List:") != NULL) {
52300
9e29d8388514 8209598: Clean up how messages are printed when CDS aborts start-up
ccheung
parents: 51444
diff changeset
   174
    vm_exit_during_cds_dumping(err_msg("-Xshare:dump does not support Extension-List in JAR manifest: %s", entry->name()));
48138
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
   175
  }
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
   176
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
   177
  char* cp_attr = get_class_path_attr(entry->name(), manifest, manifest_size);
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
   178
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
   179
  if (cp_attr != NULL && strlen(cp_attr) > 0) {
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
   180
    trace_class_path("found Class-Path: ", cp_attr);
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
   181
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
   182
    char sep = os::file_separator()[0];
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
   183
    const char* dir_name = entry->name();
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
   184
    const char* dir_tail = strrchr(dir_name, sep);
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
   185
    int dir_len;
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
   186
    if (dir_tail == NULL) {
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
   187
      dir_len = 0;
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
   188
    } else {
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
   189
      dir_len = dir_tail - dir_name + 1;
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
   190
    }
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
   191
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
   192
    // Split the cp_attr by spaces, and add each file
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
   193
    char* file_start = cp_attr;
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
   194
    char* end = file_start + strlen(file_start);
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
   195
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
   196
    while (file_start < end) {
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
   197
      char* file_end = strchr(file_start, ' ');
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
   198
      if (file_end != NULL) {
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
   199
        *file_end = 0;
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
   200
        file_end += 1;
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
   201
      } else {
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
   202
        file_end = end;
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
   203
      }
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
   204
53882
ca682d9d8db5 8214777: Avoid some GCC 8.X strncpy() errors in HotSpot
mikael
parents: 52631
diff changeset
   205
      size_t name_len = strlen(file_start);
48138
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
   206
      if (name_len > 0) {
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
   207
        ResourceMark rm(THREAD);
53882
ca682d9d8db5 8214777: Avoid some GCC 8.X strncpy() errors in HotSpot
mikael
parents: 52631
diff changeset
   208
        size_t libname_len = dir_len + name_len;
ca682d9d8db5 8214777: Avoid some GCC 8.X strncpy() errors in HotSpot
mikael
parents: 52631
diff changeset
   209
        char* libname = NEW_RESOURCE_ARRAY(char, libname_len + 1);
53908
45a23c64d0f6 8219583: Windows build failure after JDK-8214777 (Avoid some GCC 8.X strncpy() errors in HotSpot)
shade
parents: 53882
diff changeset
   210
        int n = os::snprintf(libname, libname_len + 1, "%.*s%s", dir_len, dir_name, file_start);
53882
ca682d9d8db5 8214777: Avoid some GCC 8.X strncpy() errors in HotSpot
mikael
parents: 52631
diff changeset
   211
        assert((size_t)n == libname_len, "Unexpected number of characters in string");
57898
5ddb746d45e0 8227370: Remove SharedPathsMiscInfo
iklam
parents: 55524
diff changeset
   212
        if (ClassLoader::update_class_path_entry_list(libname, true, false, true /* from_class_path_attr */)) {
5ddb746d45e0 8227370: Remove SharedPathsMiscInfo
iklam
parents: 55524
diff changeset
   213
          trace_class_path("library = ", libname);
5ddb746d45e0 8227370: Remove SharedPathsMiscInfo
iklam
parents: 55524
diff changeset
   214
        } else {
5ddb746d45e0 8227370: Remove SharedPathsMiscInfo
iklam
parents: 55524
diff changeset
   215
          trace_class_path("library (non-existent) = ", libname);
5ddb746d45e0 8227370: Remove SharedPathsMiscInfo
iklam
parents: 55524
diff changeset
   216
          FileMapInfo::record_non_existent_class_path_entry(libname);
5ddb746d45e0 8227370: Remove SharedPathsMiscInfo
iklam
parents: 55524
diff changeset
   217
        }
48138
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
   218
      }
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
   219
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
   220
      file_start = file_end;
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
   221
    }
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
   222
  }
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
   223
}
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
   224
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
   225
void ClassLoaderExt::setup_search_paths() {
49931
840e26123940 8193213: Make the UseAppCDS option obsolete.
jiangli
parents: 49739
diff changeset
   226
  ClassLoaderExt::setup_app_search_path();
49739
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents: 49341
diff changeset
   227
}
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents: 49341
diff changeset
   228
50039
9fec54fe663d 8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents: 49931
diff changeset
   229
void ClassLoaderExt::record_result(const s2 classpath_index,
48138
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
   230
                                   InstanceKlass* result,
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
   231
                                   TRAPS) {
58447
319173c62caa 8231606: _method_ordering is not set during CDS dynamic dump time
ccheung
parents: 58110
diff changeset
   232
  Arguments::assert_is_dumping_archive();
48138
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
   233
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
   234
  // We need to remember where the class comes from during dumping.
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
   235
  oop loader = result->class_loader();
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
   236
  s2 classloader_type = ClassLoader::BOOT_LOADER;
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
   237
  if (SystemDictionary::is_system_class_loader(loader)) {
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
   238
    classloader_type = ClassLoader::APP_LOADER;
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
   239
    ClassLoaderExt::set_has_app_classes();
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
   240
  } else if (SystemDictionary::is_platform_class_loader(loader)) {
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
   241
    classloader_type = ClassLoader::PLATFORM_LOADER;
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
   242
    ClassLoaderExt::set_has_platform_classes();
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
   243
  }
51439
0517bd2a0eda 8209385: CDS runtime classpath checking is too strict when only classes from the system modules are archived
ccheung
parents: 50329
diff changeset
   244
  if (classpath_index > ClassLoaderExt::max_used_path_index()) {
0517bd2a0eda 8209385: CDS runtime classpath checking is too strict when only classes from the system modules are archived
ccheung
parents: 50329
diff changeset
   245
    ClassLoaderExt::set_max_used_path_index(classpath_index);
0517bd2a0eda 8209385: CDS runtime classpath checking is too strict when only classes from the system modules are archived
ccheung
parents: 50329
diff changeset
   246
  }
48138
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
   247
  result->set_shared_classpath_index(classpath_index);
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
   248
  result->set_class_loader_type(classloader_type);
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
   249
}
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
   250
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
   251
// Load the class of the given name from the location given by path. The path is specified by
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
   252
// the "source:" in the class list file (see classListParser.cpp), and can be a directory or
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
   253
// a JAR file.
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
   254
InstanceKlass* ClassLoaderExt::load_class(Symbol* name, const char* path, TRAPS) {
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
   255
  assert(name != NULL, "invariant");
49931
840e26123940 8193213: Make the UseAppCDS option obsolete.
jiangli
parents: 49739
diff changeset
   256
  assert(DumpSharedSpaces, "this function is only used with -Xshare:dump");
48138
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
   257
  ResourceMark rm(THREAD);
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
   258
  const char* class_name = name->as_C_string();
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
   259
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
   260
  const char* file_name = file_name_for_class_name(class_name,
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
   261
                                                   name->utf8_length());
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
   262
  assert(file_name != NULL, "invariant");
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
   263
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
   264
  // Lookup stream for parsing .class file
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
   265
  ClassFileStream* stream = NULL;
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
   266
  ClassPathEntry* e = find_classpath_entry_from_cache(path, CHECK_NULL);
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
   267
  if (e == NULL) {
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
   268
    return NULL;
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
   269
  }
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
   270
  {
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
   271
    PerfClassTraceTime vmtimer(perf_sys_class_lookup_time(),
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
   272
                               ((JavaThread*) THREAD)->get_thread_stat()->perf_timers_addr(),
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
   273
                               PerfClassTraceTime::CLASS_LOAD);
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
   274
    stream = e->open_stream(file_name, CHECK_NULL);
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
   275
  }
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
   276
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
   277
  if (NULL == stream) {
58110
85e1de070bef 8186988: use log_warning() and log_error() instead of tty->print_cr for CDS warning and error messages
ccheung
parents: 58096
diff changeset
   278
    log_warning(cds)("Preload Warning: Cannot find %s", class_name);
48138
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
   279
    return NULL;
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
   280
  }
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
   281
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
   282
  assert(stream != NULL, "invariant");
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
   283
  stream->set_verify(true);
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
   284
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
   285
  ClassLoaderData* loader_data = ClassLoaderData::the_null_class_loader_data();
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
   286
  Handle protection_domain;
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
   287
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
   288
  InstanceKlass* result = KlassFactory::create_from_stream(stream,
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
   289
                                                           name,
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
   290
                                                           loader_data,
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
   291
                                                           protection_domain,
51444
3e5d28e6de32 8209301: JVM rename is_anonymous, host_klass to unsafe specific terminology ahead of Unsafe.defineAnonymousClass deprecation
lfoltan
parents: 51439
diff changeset
   292
                                                           NULL, // unsafe_anonymous_host
48138
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
   293
                                                           NULL, // cp_patches
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
   294
                                                           THREAD);
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
   295
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
   296
  if (HAS_PENDING_EXCEPTION) {
58110
85e1de070bef 8186988: use log_warning() and log_error() instead of tty->print_cr for CDS warning and error messages
ccheung
parents: 58096
diff changeset
   297
    log_error(cds)("Preload Error: Failed to load %s", class_name);
48138
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
   298
    return NULL;
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
   299
  }
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
   300
  return result;
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
   301
}
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
   302
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
   303
struct CachedClassPathEntry {
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
   304
  const char* _path;
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
   305
  ClassPathEntry* _entry;
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
   306
};
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
   307
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
   308
static GrowableArray<CachedClassPathEntry>* cached_path_entries = NULL;
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
   309
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
   310
ClassPathEntry* ClassLoaderExt::find_classpath_entry_from_cache(const char* path, TRAPS) {
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
   311
  // This is called from dump time so it's single threaded and there's no need for a lock.
49931
840e26123940 8193213: Make the UseAppCDS option obsolete.
jiangli
parents: 49739
diff changeset
   312
  assert(DumpSharedSpaces, "this function is only used with -Xshare:dump");
48138
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
   313
  if (cached_path_entries == NULL) {
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
   314
    cached_path_entries = new (ResourceObj::C_HEAP, mtClass) GrowableArray<CachedClassPathEntry>(20, /*c heap*/ true);
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
   315
  }
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
   316
  CachedClassPathEntry ccpe;
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
   317
  for (int i=0; i<cached_path_entries->length(); i++) {
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
   318
    ccpe = cached_path_entries->at(i);
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
   319
    if (strcmp(ccpe._path, path) == 0) {
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
   320
      if (i != 0) {
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
   321
        // Put recent entries at the beginning to speed up searches.
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
   322
        cached_path_entries->remove_at(i);
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
   323
        cached_path_entries->insert_before(0, ccpe);
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
   324
      }
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
   325
      return ccpe._entry;
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
   326
    }
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
   327
  }
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
   328
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
   329
  struct stat st;
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
   330
  if (os::stat(path, &st) != 0) {
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
   331
    // File or directory not found
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
   332
    return NULL;
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
   333
  }
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
   334
  ClassPathEntry* new_entry = NULL;
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
   335
55524
b279ae9843b8 8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents: 54927
diff changeset
   336
  new_entry = create_class_path_entry(path, &st, false, false, false, CHECK_NULL);
48138
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
   337
  if (new_entry == NULL) {
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
   338
    return NULL;
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
   339
  }
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
   340
  ccpe._path = strdup(path);
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
   341
  ccpe._entry = new_entry;
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
   342
  cached_path_entries->insert_before(0, ccpe);
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
   343
  return new_entry;
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
   344
}