Skip to content
Permalink
Browse files
8266851: Implement JEP 403: Strongly Encapsulate JDK Internals
Co-authored-by: Alan Bateman <alanb@openjdk.org>
Reviewed-by: mchung, alanb, hseigel
  • Loading branch information
mbreinhold and Alan Bateman committed May 26, 2021
1 parent 8c4719a commit e63023546aaf48ae39c72ab37f6ef3f5474e19cc
Showing with 50 additions and 2,842 deletions.
  1. +4 −7 src/hotspot/share/runtime/arguments.cpp
  2. +3 −24 src/java.base/share/classes/java/lang/Module.java
  3. +0 −8 src/java.base/share/classes/java/lang/invoke/MethodHandles.java
  4. +0 −31 src/java.base/share/classes/java/lang/reflect/AccessibleObject.java
  5. +1 −11 src/java.base/share/classes/jdk/internal/module/ExplodedSystemModules.java
  6. +0 −407 src/java.base/share/classes/jdk/internal/module/IllegalAccessLogger.java
  7. +0 −130 src/java.base/share/classes/jdk/internal/module/IllegalAccessMaps.java
  8. +4 −107 src/java.base/share/classes/jdk/internal/module/ModuleBootstrap.java
  9. +1 −13 src/java.base/share/classes/jdk/internal/module/SystemModules.java
  10. +0 −1,340 src/java.base/share/classes/jdk/internal/module/jdk8_packages.dat
  11. +1 −6 src/java.base/share/classes/sun/launcher/resources/launcher.properties
  12. +1 −15 src/jdk.jlink/share/classes/jdk/tools/jlink/internal/plugins/SystemModulesPlugin.java
  13. +2 −2 test/jdk/java/lang/ModuleTests/BasicModuleTest.java
  14. +2 −2 test/jdk/java/lang/instrument/RedefineModuleTest.java
  15. +2 −2 test/jdk/java/lang/invoke/CallerSensitiveAccess.java
  16. +2 −2 test/jdk/java/lang/reflect/AccessibleObject/CanAccessTest.java
  17. +2 −2 test/jdk/java/lang/reflect/AccessibleObject/ModuleSetAccessibleTest.java
  18. +2 −2 test/jdk/java/lang/reflect/AccessibleObject/TrySetAccessibleTest.java
  19. +1 −3 test/jdk/java/util/ResourceBundle/modules/cache/CacheTest.java
  20. +2 −2 test/jdk/jdk/modules/open/Basic.java
  21. +2 −3 test/jdk/tools/launcher/modules/addexports/manifest/AddExportsAndOpensInManifest.java
  22. +18 −436 test/jdk/tools/launcher/modules/illegalaccess/IllegalAccessTest.java
  23. +0 −188 test/jdk/tools/launcher/modules/illegalaccess/TryAccess.java
  24. +0 −26 test/jdk/tools/launcher/modules/illegalaccess/modules/m/module-info.java
  25. +0 −31 test/jdk/tools/launcher/modules/illegalaccess/modules/m/p/Type.java
  26. +0 −42 test/jdk/tools/launcher/modules/illegalaccess/patchsrc/java.base/java/lang/Helper.java
@@ -1330,7 +1330,6 @@ bool Arguments::add_property(const char* prop, PropertyWriteable writeable, Prop
log_info(cds)("optimized module handling: disabled due to incompatible property: %s=%s", key, value);
}
if (strcmp(key, "jdk.module.showModuleResolution") == 0 ||
strcmp(key, "jdk.module.illegalAccess") == 0 ||
strcmp(key, "jdk.module.validation") == 0 ||
strcmp(key, "java.system.class.loader") == 0) {
MetaspaceShared::disable_full_module_graph();
@@ -2061,8 +2060,7 @@ bool Arguments::parse_uintx(const char* value,
}

bool Arguments::create_module_property(const char* prop_name, const char* prop_value, PropertyInternal internal) {
assert(is_internal_module_property(prop_name) ||
strcmp(prop_name, "jdk.module.illegalAccess") == 0, "unknown module property: '%s'", prop_name);
assert(is_internal_module_property(prop_name), "unknown module property: '%s'", prop_name);
size_t prop_len = strlen(prop_name) + strlen(prop_value) + 2;
char* property = AllocateHeap(prop_len, mtArguments);
int ret = jio_snprintf(property, prop_len, "%s=%s", prop_name, prop_value);
@@ -2427,10 +2425,9 @@ jint Arguments::parse_each_vm_init_arg(const JavaVMInitArgs* args, bool* patch_m
return res;
}
} else if (match_option(option, "--illegal-access=", &tail)) {
warning("Option --illegal-access is deprecated and will be removed in a future release.");
if (!create_module_property("jdk.module.illegalAccess", tail, ExternalProperty)) {
return JNI_ENOMEM;
}
char version[256];
JDK_Version::jdk(17).to_string(version, sizeof(version));
warning("Ignoring option %s; support was removed in %s", option->optionString, version);
// -agentlib and -agentpath
} else if (match_option(option, "-agentlib:", &tail) ||
(is_absolute_path = match_option(option, "-agentpath:", &tail))) {
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2014, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2014, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -56,8 +56,6 @@
import jdk.internal.loader.BootLoader;
import jdk.internal.loader.ClassLoaders;
import jdk.internal.misc.CDS;
import jdk.internal.misc.VM;
import jdk.internal.module.IllegalAccessLogger;
import jdk.internal.module.ModuleLoaderMap;
import jdk.internal.module.ServicesCatalog;
import jdk.internal.module.Resources;
@@ -903,27 +901,8 @@ private void implAddExportsOrOpens(String pn,
return;

// check if the package is already exported/open to other
if (implIsExportedOrOpen(pn, other, open)) {

// if the package is exported/open for illegal access then we need
// to record that it has also been exported/opened reflectively so
// that the IllegalAccessLogger doesn't emit a warning.
boolean needToAdd = false;
if (!other.isNamed()) {
IllegalAccessLogger l = IllegalAccessLogger.illegalAccessLogger();
if (l != null) {
if (open) {
needToAdd = l.isOpenForIllegalAccess(this, pn);
} else {
needToAdd = l.isExportedForIllegalAccess(this, pn);
}
}
}
if (!needToAdd) {
// nothing to do
return;
}
}
if (implIsExportedOrOpen(pn, other, open))
return;

// can only export a package in the module
if (!descriptor.packages().contains(pn)) {
@@ -28,7 +28,6 @@
import jdk.internal.access.SharedSecrets;
import jdk.internal.misc.Unsafe;
import jdk.internal.misc.VM;
import jdk.internal.module.IllegalAccessLogger;
import jdk.internal.org.objectweb.asm.ClassReader;
import jdk.internal.org.objectweb.asm.Opcodes;
import jdk.internal.org.objectweb.asm.Type;
@@ -262,13 +261,6 @@ public static Lookup privateLookupIn(Class<?> targetClass, Lookup caller) throws
// M2 != M1, set previous lookup class to M1 and drop MODULE access
newPreviousClass = callerClass;
newModes &= ~Lookup.MODULE;

if (!callerModule.isNamed() && targetModule.isNamed()) {
IllegalAccessLogger logger = IllegalAccessLogger.illegalAccessLogger();
if (logger != null) {
logger.logIfOpenedForIllegalAccess(caller, targetClass);
}
}
}
return Lookup.newLookup(targetClass, newPreviousClass, newModes);
}
@@ -32,7 +32,6 @@

import jdk.internal.access.SharedSecrets;
import jdk.internal.misc.VM;
import jdk.internal.module.IllegalAccessLogger;
import jdk.internal.reflect.CallerSensitive;
import jdk.internal.reflect.Reflection;
import jdk.internal.reflect.ReflectionFactory;
@@ -324,22 +323,19 @@ private boolean checkCanSetAccessible(Class<?> caller,
if (isClassPublic && declaringModule.isExported(pn, callerModule)) {
// member is public
if (Modifier.isPublic(modifiers)) {
logIfExportedForIllegalAccess(caller, declaringClass);
return true;
}

// member is protected-static
if (Modifier.isProtected(modifiers)
&& Modifier.isStatic(modifiers)
&& isSubclassOf(caller, declaringClass)) {
logIfExportedForIllegalAccess(caller, declaringClass);
return true;
}
}

// package is open to caller
if (declaringModule.isOpen(pn, callerModule)) {
logIfOpenedForIllegalAccess(caller, declaringClass);
return true;
}

@@ -373,30 +369,6 @@ private boolean isSubclassOf(Class<?> queryClass, Class<?> ofClass) {
return false;
}

private void logIfOpenedForIllegalAccess(Class<?> caller, Class<?> declaringClass) {
Module callerModule = caller.getModule();
Module targetModule = declaringClass.getModule();
// callerModule is null during early startup
if (callerModule != null && !callerModule.isNamed() && targetModule.isNamed()) {
IllegalAccessLogger logger = IllegalAccessLogger.illegalAccessLogger();
if (logger != null) {
logger.logIfOpenedForIllegalAccess(caller, declaringClass, this::toShortString);
}
}
}

private void logIfExportedForIllegalAccess(Class<?> caller, Class<?> declaringClass) {
Module callerModule = caller.getModule();
Module targetModule = declaringClass.getModule();
// callerModule is null during early startup
if (callerModule != null && !callerModule.isNamed() && targetModule.isNamed()) {
IllegalAccessLogger logger = IllegalAccessLogger.illegalAccessLogger();
if (logger != null) {
logger.logIfExportedForIllegalAccess(caller, declaringClass, this::toShortString);
}
}
}

/**
* Returns a short descriptive string to describe this object in log messages.
*/
@@ -743,9 +715,6 @@ private boolean slowVerifyAccess(Class<?> caller, Class<?> memberClass,
return false;
}

// access okay
logIfExportedForIllegalAccess(caller, memberClass);

// Success: Update the cache.
Object cache = (targetClass != null
&& Modifier.isProtected(modifiers)
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2017, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -68,14 +68,4 @@ public boolean hasIncubatorModules() {
public Map<String, Set<String>> moduleReads() {
throw new InternalError();
}

@Override
public Map<String, Set<String>> concealedPackagesToOpen() {
return Map.of();
}

@Override
public Map<String, Set<String>> exportedPackagesToOpen() {
return Map.of();
}
}

2 comments on commit e630235

@openjdk-notifier

This comment has been minimized.

Copy link

@openjdk-notifier openjdk-notifier bot replied May 26, 2021

@camdenorrb

This comment has been minimized.

Copy link

@camdenorrb camdenorrb replied Jun 1, 2021

Hi @camdenorrb, thanks for making a comment in an OpenJDK project!

All comments and discussions in the OpenJDK Community must be made available under the OpenJDK Terms of Use. If you already are an OpenJDK Author, Committer or Reviewer, please click here to open a new issue so that we can record that fact. Please Use "Add GitHub user camdenorrb for the summary.

If you are not an OpenJDK Author, Committer or Reviewer, simply check the box below to accept the OpenJDK Terms of Use for your comments.

Your comment will be automatically restored once you have accepted the OpenJDK Terms of Use.

Please sign in to comment.