Skip to content

Commit e630235

Browse files
mbreinholdAlan Bateman
andcommitted
8266851: Implement JEP 403: Strongly Encapsulate JDK Internals
Co-authored-by: Alan Bateman <alanb@openjdk.org> Reviewed-by: mchung, alanb, hseigel
1 parent 8c4719a commit e630235

File tree

26 files changed

+50
-2842
lines changed

26 files changed

+50
-2842
lines changed

src/hotspot/share/runtime/arguments.cpp

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1330,7 +1330,6 @@ bool Arguments::add_property(const char* prop, PropertyWriteable writeable, Prop
13301330
log_info(cds)("optimized module handling: disabled due to incompatible property: %s=%s", key, value);
13311331
}
13321332
if (strcmp(key, "jdk.module.showModuleResolution") == 0 ||
1333-
strcmp(key, "jdk.module.illegalAccess") == 0 ||
13341333
strcmp(key, "jdk.module.validation") == 0 ||
13351334
strcmp(key, "java.system.class.loader") == 0) {
13361335
MetaspaceShared::disable_full_module_graph();
@@ -2061,8 +2060,7 @@ bool Arguments::parse_uintx(const char* value,
20612060
}
20622061

20632062
bool Arguments::create_module_property(const char* prop_name, const char* prop_value, PropertyInternal internal) {
2064-
assert(is_internal_module_property(prop_name) ||
2065-
strcmp(prop_name, "jdk.module.illegalAccess") == 0, "unknown module property: '%s'", prop_name);
2063+
assert(is_internal_module_property(prop_name), "unknown module property: '%s'", prop_name);
20662064
size_t prop_len = strlen(prop_name) + strlen(prop_value) + 2;
20672065
char* property = AllocateHeap(prop_len, mtArguments);
20682066
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
24272425
return res;
24282426
}
24292427
} else if (match_option(option, "--illegal-access=", &tail)) {
2430-
warning("Option --illegal-access is deprecated and will be removed in a future release.");
2431-
if (!create_module_property("jdk.module.illegalAccess", tail, ExternalProperty)) {
2432-
return JNI_ENOMEM;
2433-
}
2428+
char version[256];
2429+
JDK_Version::jdk(17).to_string(version, sizeof(version));
2430+
warning("Ignoring option %s; support was removed in %s", option->optionString, version);
24342431
// -agentlib and -agentpath
24352432
} else if (match_option(option, "-agentlib:", &tail) ||
24362433
(is_absolute_path = match_option(option, "-agentpath:", &tail))) {

src/java.base/share/classes/java/lang/Module.java

Lines changed: 3 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2014, 2020, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2014, 2021, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -56,8 +56,6 @@
5656
import jdk.internal.loader.BootLoader;
5757
import jdk.internal.loader.ClassLoaders;
5858
import jdk.internal.misc.CDS;
59-
import jdk.internal.misc.VM;
60-
import jdk.internal.module.IllegalAccessLogger;
6159
import jdk.internal.module.ModuleLoaderMap;
6260
import jdk.internal.module.ServicesCatalog;
6361
import jdk.internal.module.Resources;
@@ -903,27 +901,8 @@ private void implAddExportsOrOpens(String pn,
903901
return;
904902

905903
// check if the package is already exported/open to other
906-
if (implIsExportedOrOpen(pn, other, open)) {
907-
908-
// if the package is exported/open for illegal access then we need
909-
// to record that it has also been exported/opened reflectively so
910-
// that the IllegalAccessLogger doesn't emit a warning.
911-
boolean needToAdd = false;
912-
if (!other.isNamed()) {
913-
IllegalAccessLogger l = IllegalAccessLogger.illegalAccessLogger();
914-
if (l != null) {
915-
if (open) {
916-
needToAdd = l.isOpenForIllegalAccess(this, pn);
917-
} else {
918-
needToAdd = l.isExportedForIllegalAccess(this, pn);
919-
}
920-
}
921-
}
922-
if (!needToAdd) {
923-
// nothing to do
924-
return;
925-
}
926-
}
904+
if (implIsExportedOrOpen(pn, other, open))
905+
return;
927906

928907
// can only export a package in the module
929908
if (!descriptor.packages().contains(pn)) {

src/java.base/share/classes/java/lang/invoke/MethodHandles.java

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
import jdk.internal.access.SharedSecrets;
2929
import jdk.internal.misc.Unsafe;
3030
import jdk.internal.misc.VM;
31-
import jdk.internal.module.IllegalAccessLogger;
3231
import jdk.internal.org.objectweb.asm.ClassReader;
3332
import jdk.internal.org.objectweb.asm.Opcodes;
3433
import jdk.internal.org.objectweb.asm.Type;
@@ -262,13 +261,6 @@ public static Lookup privateLookupIn(Class<?> targetClass, Lookup caller) throws
262261
// M2 != M1, set previous lookup class to M1 and drop MODULE access
263262
newPreviousClass = callerClass;
264263
newModes &= ~Lookup.MODULE;
265-
266-
if (!callerModule.isNamed() && targetModule.isNamed()) {
267-
IllegalAccessLogger logger = IllegalAccessLogger.illegalAccessLogger();
268-
if (logger != null) {
269-
logger.logIfOpenedForIllegalAccess(caller, targetClass);
270-
}
271-
}
272264
}
273265
return Lookup.newLookup(targetClass, newPreviousClass, newModes);
274266
}

src/java.base/share/classes/java/lang/reflect/AccessibleObject.java

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232

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

331329
// member is protected-static
332330
if (Modifier.isProtected(modifiers)
333331
&& Modifier.isStatic(modifiers)
334332
&& isSubclassOf(caller, declaringClass)) {
335-
logIfExportedForIllegalAccess(caller, declaringClass);
336333
return true;
337334
}
338335
}
339336

340337
// package is open to caller
341338
if (declaringModule.isOpen(pn, callerModule)) {
342-
logIfOpenedForIllegalAccess(caller, declaringClass);
343339
return true;
344340
}
345341

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

376-
private void logIfOpenedForIllegalAccess(Class<?> caller, Class<?> declaringClass) {
377-
Module callerModule = caller.getModule();
378-
Module targetModule = declaringClass.getModule();
379-
// callerModule is null during early startup
380-
if (callerModule != null && !callerModule.isNamed() && targetModule.isNamed()) {
381-
IllegalAccessLogger logger = IllegalAccessLogger.illegalAccessLogger();
382-
if (logger != null) {
383-
logger.logIfOpenedForIllegalAccess(caller, declaringClass, this::toShortString);
384-
}
385-
}
386-
}
387-
388-
private void logIfExportedForIllegalAccess(Class<?> caller, Class<?> declaringClass) {
389-
Module callerModule = caller.getModule();
390-
Module targetModule = declaringClass.getModule();
391-
// callerModule is null during early startup
392-
if (callerModule != null && !callerModule.isNamed() && targetModule.isNamed()) {
393-
IllegalAccessLogger logger = IllegalAccessLogger.illegalAccessLogger();
394-
if (logger != null) {
395-
logger.logIfExportedForIllegalAccess(caller, declaringClass, this::toShortString);
396-
}
397-
}
398-
}
399-
400372
/**
401373
* Returns a short descriptive string to describe this object in log messages.
402374
*/
@@ -743,9 +715,6 @@ private boolean slowVerifyAccess(Class<?> caller, Class<?> memberClass,
743715
return false;
744716
}
745717

746-
// access okay
747-
logIfExportedForIllegalAccess(caller, memberClass);
748-
749718
// Success: Update the cache.
750719
Object cache = (targetClass != null
751720
&& Modifier.isProtected(modifiers)

src/java.base/share/classes/jdk/internal/module/ExplodedSystemModules.java

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2017, 2021, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -68,14 +68,4 @@ public ModuleResolution[] moduleResolutions() {
6868
public Map<String, Set<String>> moduleReads() {
6969
throw new InternalError();
7070
}
71-
72-
@Override
73-
public Map<String, Set<String>> concealedPackagesToOpen() {
74-
return Map.of();
75-
}
76-
77-
@Override
78-
public Map<String, Set<String>> exportedPackagesToOpen() {
79-
return Map.of();
80-
}
8171
}

0 commit comments

Comments
 (0)