mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-28 07:14:30 +02:00
8174823: Module system implementation refresh (3/2017)
Reviewed-by: sspitsyn, dholmes, lfoltan, mchung
This commit is contained in:
parent
a085f48913
commit
73165d34e4
8 changed files with 49 additions and 25 deletions
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
|
@ -36,8 +36,8 @@
|
||||||
#include "utilities/ostream.hpp"
|
#include "utilities/ostream.hpp"
|
||||||
|
|
||||||
#define UNNAMED_MODULE "Unnamed Module"
|
#define UNNAMED_MODULE "Unnamed Module"
|
||||||
#define JAVAPKG "java/"
|
#define JAVAPKG "java"
|
||||||
#define JAVAPKG_LEN 5
|
#define JAVAPKG_LEN 4
|
||||||
#define JAVA_BASE_NAME "java.base"
|
#define JAVA_BASE_NAME "java.base"
|
||||||
|
|
||||||
class ModuleClosure;
|
class ModuleClosure;
|
||||||
|
|
|
@ -325,7 +325,8 @@ void Modules::define_module(jobject module, jstring version,
|
||||||
// Only modules defined to either the boot or platform class loader, can define a "java/" package.
|
// Only modules defined to either the boot or platform class loader, can define a "java/" package.
|
||||||
if (!h_loader.is_null() &&
|
if (!h_loader.is_null() &&
|
||||||
!SystemDictionary::is_platform_class_loader(h_loader) &&
|
!SystemDictionary::is_platform_class_loader(h_loader) &&
|
||||||
strncmp(package_name, JAVAPKG, JAVAPKG_LEN) == 0) {
|
(strncmp(package_name, JAVAPKG, JAVAPKG_LEN) == 0 &&
|
||||||
|
(package_name[JAVAPKG_LEN] == '/' || package_name[JAVAPKG_LEN] == '\0'))) {
|
||||||
const char* class_loader_name = SystemDictionary::loader_name(h_loader());
|
const char* class_loader_name = SystemDictionary::loader_name(h_loader());
|
||||||
size_t pkg_len = strlen(package_name);
|
size_t pkg_len = strlen(package_name);
|
||||||
char* pkg_name = NEW_RESOURCE_ARRAY_IN_THREAD(THREAD, char, pkg_len);
|
char* pkg_name = NEW_RESOURCE_ARRAY_IN_THREAD(THREAD, char, pkg_len);
|
||||||
|
@ -748,7 +749,8 @@ void Modules::add_module_package(jobject module, const char* package_name, TRAPS
|
||||||
// Only modules defined to either the boot or platform class loader, can define a "java/" package.
|
// Only modules defined to either the boot or platform class loader, can define a "java/" package.
|
||||||
if (!loader_data->is_the_null_class_loader_data() &&
|
if (!loader_data->is_the_null_class_loader_data() &&
|
||||||
!loader_data->is_platform_class_loader_data() &&
|
!loader_data->is_platform_class_loader_data() &&
|
||||||
strncmp(package_name, JAVAPKG, JAVAPKG_LEN) == 0) {
|
(strncmp(package_name, JAVAPKG, JAVAPKG_LEN) == 0 &&
|
||||||
|
(package_name[JAVAPKG_LEN] == '/' || package_name[JAVAPKG_LEN] == '\0'))) {
|
||||||
const char* class_loader_name = SystemDictionary::loader_name(loader_data);
|
const char* class_loader_name = SystemDictionary::loader_name(loader_data);
|
||||||
size_t pkg_len = strlen(package_name);
|
size_t pkg_len = strlen(package_name);
|
||||||
char* pkg_name = NEW_RESOURCE_ARRAY_IN_THREAD(THREAD, char, pkg_len);
|
char* pkg_name = NEW_RESOURCE_ARRAY_IN_THREAD(THREAD, char, pkg_len);
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved.
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
|
@ -561,6 +561,7 @@
|
||||||
template(int_StringBuffer_signature, "(I)Ljava/lang/StringBuffer;") \
|
template(int_StringBuffer_signature, "(I)Ljava/lang/StringBuffer;") \
|
||||||
template(char_StringBuffer_signature, "(C)Ljava/lang/StringBuffer;") \
|
template(char_StringBuffer_signature, "(C)Ljava/lang/StringBuffer;") \
|
||||||
template(int_String_signature, "(I)Ljava/lang/String;") \
|
template(int_String_signature, "(I)Ljava/lang/String;") \
|
||||||
|
template(boolean_boolean_int_signature, "(ZZ)I") \
|
||||||
template(codesource_permissioncollection_signature, "(Ljava/security/CodeSource;Ljava/security/PermissionCollection;)V") \
|
template(codesource_permissioncollection_signature, "(Ljava/security/CodeSource;Ljava/security/PermissionCollection;)V") \
|
||||||
/* signature symbols needed by intrinsics */ \
|
/* signature symbols needed by intrinsics */ \
|
||||||
VM_INTRINSICS_DO(VM_INTRINSIC_IGNORE, VM_SYMBOL_IGNORE, VM_SYMBOL_IGNORE, template, VM_ALIAS_IGNORE) \
|
VM_INTRINSICS_DO(VM_INTRINSIC_IGNORE, VM_SYMBOL_IGNORE, VM_SYMBOL_IGNORE, template, VM_ALIAS_IGNORE) \
|
||||||
|
|
|
@ -2456,22 +2456,24 @@ Klass* InstanceKlass::compute_enclosing_class_impl(instanceKlassHandle self,
|
||||||
void InstanceKlass::check_prohibited_package(Symbol* class_name,
|
void InstanceKlass::check_prohibited_package(Symbol* class_name,
|
||||||
Handle class_loader,
|
Handle class_loader,
|
||||||
TRAPS) {
|
TRAPS) {
|
||||||
ResourceMark rm(THREAD);
|
|
||||||
if (!class_loader.is_null() &&
|
if (!class_loader.is_null() &&
|
||||||
!SystemDictionary::is_platform_class_loader(class_loader) &&
|
!SystemDictionary::is_platform_class_loader(class_loader) &&
|
||||||
class_name != NULL &&
|
class_name != NULL) {
|
||||||
strncmp(class_name->as_C_string(), JAVAPKG, JAVAPKG_LEN) == 0) {
|
ResourceMark rm(THREAD);
|
||||||
TempNewSymbol pkg_name = InstanceKlass::package_from_name(class_name, CHECK);
|
char* name = class_name->as_C_string();
|
||||||
assert(pkg_name != NULL, "Error in parsing package name starting with 'java/'");
|
if (strncmp(name, JAVAPKG, JAVAPKG_LEN) == 0 && name[JAVAPKG_LEN] == '/') {
|
||||||
char* name = pkg_name->as_C_string();
|
TempNewSymbol pkg_name = InstanceKlass::package_from_name(class_name, CHECK);
|
||||||
const char* class_loader_name = SystemDictionary::loader_name(class_loader());
|
assert(pkg_name != NULL, "Error in parsing package name starting with 'java/'");
|
||||||
StringUtils::replace_no_expand(name, "/", ".");
|
name = pkg_name->as_C_string();
|
||||||
const char* msg_text1 = "Class loader (instance of): ";
|
const char* class_loader_name = SystemDictionary::loader_name(class_loader());
|
||||||
const char* msg_text2 = " tried to load prohibited package name: ";
|
StringUtils::replace_no_expand(name, "/", ".");
|
||||||
size_t len = strlen(msg_text1) + strlen(class_loader_name) + strlen(msg_text2) + strlen(name) + 1;
|
const char* msg_text1 = "Class loader (instance of): ";
|
||||||
char* message = NEW_RESOURCE_ARRAY_IN_THREAD(THREAD, char, len);
|
const char* msg_text2 = " tried to load prohibited package name: ";
|
||||||
jio_snprintf(message, len, "%s%s%s%s", msg_text1, class_loader_name, msg_text2, name);
|
size_t len = strlen(msg_text1) + strlen(class_loader_name) + strlen(msg_text2) + strlen(name) + 1;
|
||||||
THROW_MSG(vmSymbols::java_lang_SecurityException(), message);
|
char* message = NEW_RESOURCE_ARRAY_IN_THREAD(THREAD, char, len);
|
||||||
|
jio_snprintf(message, len, "%s%s%s%s", msg_text1, class_loader_name, msg_text2, name);
|
||||||
|
THROW_MSG(vmSymbols::java_lang_SecurityException(), message);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -2932,6 +2932,10 @@ jint Arguments::parse_each_vm_init_arg(const JavaVMInitArgs* args, bool* patch_m
|
||||||
if (res != JNI_OK) {
|
if (res != JNI_OK) {
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
} else if (match_option(option, "--permit-illegal-access")) {
|
||||||
|
if (!create_property("jdk.module.permitIllegalAccess", "true", ExternalProperty)) {
|
||||||
|
return JNI_ENOMEM;
|
||||||
|
}
|
||||||
// -agentlib and -agentpath
|
// -agentlib and -agentpath
|
||||||
} else if (match_option(option, "-agentlib:", &tail) ||
|
} else if (match_option(option, "-agentlib:", &tail) ||
|
||||||
(is_absolute_path = match_option(option, "-agentpath:", &tail))) {
|
(is_absolute_path = match_option(option, "-agentpath:", &tail))) {
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved.
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
|
@ -621,6 +621,13 @@ void vm_notify_during_shutdown(const char* error, const char* message) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void vm_exit_during_initialization() {
|
||||||
|
vm_notify_during_shutdown(NULL, NULL);
|
||||||
|
|
||||||
|
// Failure during initialization, we don't want to dump core
|
||||||
|
vm_abort(false);
|
||||||
|
}
|
||||||
|
|
||||||
void vm_exit_during_initialization(Handle exception) {
|
void vm_exit_during_initialization(Handle exception) {
|
||||||
tty->print_cr("Error occurred during initialization of VM");
|
tty->print_cr("Error occurred during initialization of VM");
|
||||||
// If there are exceptions on this thread it must be cleared
|
// If there are exceptions on this thread it must be cleared
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 1997, 2015, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved.
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
|
@ -45,6 +45,7 @@ extern void vm_abort(bool dump_core=true);
|
||||||
extern void notify_vm_shutdown();
|
extern void notify_vm_shutdown();
|
||||||
|
|
||||||
// VM exit if error occurs during initialization of VM
|
// VM exit if error occurs during initialization of VM
|
||||||
|
extern void vm_exit_during_initialization();
|
||||||
extern void vm_exit_during_initialization(Handle exception);
|
extern void vm_exit_during_initialization(Handle exception);
|
||||||
extern void vm_exit_during_initialization(Symbol* exception_name, const char* message);
|
extern void vm_exit_during_initialization(Symbol* exception_name, const char* message);
|
||||||
extern void vm_exit_during_initialization(const char* error, const char* message = NULL);
|
extern void vm_exit_during_initialization(const char* error, const char* message = NULL);
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved.
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
|
@ -3409,9 +3409,16 @@ static void call_initPhase2(TRAPS) {
|
||||||
Klass* k = SystemDictionary::resolve_or_fail(vmSymbols::java_lang_System(), true, CHECK);
|
Klass* k = SystemDictionary::resolve_or_fail(vmSymbols::java_lang_System(), true, CHECK);
|
||||||
instanceKlassHandle klass (THREAD, k);
|
instanceKlassHandle klass (THREAD, k);
|
||||||
|
|
||||||
JavaValue result(T_VOID);
|
JavaValue result(T_INT);
|
||||||
|
JavaCallArguments args;
|
||||||
|
args.push_int(DisplayVMOutputToStderr);
|
||||||
|
args.push_int(log_is_enabled(Debug, init)); // print stack trace if exception thrown
|
||||||
JavaCalls::call_static(&result, klass, vmSymbols::initPhase2_name(),
|
JavaCalls::call_static(&result, klass, vmSymbols::initPhase2_name(),
|
||||||
vmSymbols::void_method_signature(), CHECK);
|
vmSymbols::boolean_boolean_int_signature(), &args, CHECK);
|
||||||
|
if (result.get_jint() != JNI_OK) {
|
||||||
|
vm_exit_during_initialization(); // no message or exception
|
||||||
|
}
|
||||||
|
|
||||||
universe_post_module_init();
|
universe_post_module_init();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue