forked from PojavLauncherTeam/mobile
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathe63023546aaf48ae39c72ab37f6ef3f5474e19cc.patch
3397 lines (3362 loc) · 127 KB
/
e63023546aaf48ae39c72ab37f6ef3f5474e19cc.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
From e63023546aaf48ae39c72ab37f6ef3f5474e19cc Mon Sep 17 00:00:00 2001
From: Mark Reinhold <[email protected]>
Date: Wed, 26 May 2021 20:55:53 +0000
Subject: [PATCH] 8266851: Implement JEP 403: Strongly Encapsulate JDK
Internals
Co-authored-by: Alan Bateman <[email protected]>
Reviewed-by: mchung, alanb, hseigel
---
src/hotspot/share/runtime/arguments.cpp | 11 +-
.../share/classes/java/lang/Module.java | 27 +-
.../java/lang/invoke/MethodHandles.java | 8 -
.../java/lang/reflect/AccessibleObject.java | 31 -
.../module/ExplodedSystemModules.java | 12 +-
.../internal/module/IllegalAccessLogger.java | 407 -----
.../internal/module/IllegalAccessMaps.java | 130 --
.../jdk/internal/module/ModuleBootstrap.java | 111 +-
.../jdk/internal/module/SystemModules.java | 14 +-
.../jdk/internal/module/jdk8_packages.dat | 1340 -----------------
.../launcher/resources/launcher.properties | 7 +-
.../internal/plugins/SystemModulesPlugin.java | 16 +-
.../lang/ModuleTests/BasicModuleTest.java | 4 +-
.../lang/instrument/RedefineModuleTest.java | 4 +-
.../lang/invoke/CallerSensitiveAccess.java | 4 +-
.../AccessibleObject/CanAccessTest.java | 4 +-
.../ModuleSetAccessibleTest.java | 4 +-
.../TrySetAccessibleTest.java | 4 +-
.../modules/cache/CacheTest.java | 4 +-
test/jdk/jdk/modules/open/Basic.java | 4 +-
.../AddExportsAndOpensInManifest.java | 5 +-
.../illegalaccess/IllegalAccessTest.java | 454 +-----
.../modules/illegalaccess/TryAccess.java | 188 ---
.../illegalaccess/modules/m/module-info.java | 26 -
.../illegalaccess/modules/m/p/Type.java | 31 -
.../patchsrc/java.base/java/lang/Helper.java | 42 -
26 files changed, 50 insertions(+), 2842 deletions(-)
delete mode 100644 src/java.base/share/classes/jdk/internal/module/IllegalAccessLogger.java
delete mode 100644 src/java.base/share/classes/jdk/internal/module/IllegalAccessMaps.java
delete mode 100644 src/java.base/share/classes/jdk/internal/module/jdk8_packages.dat
delete mode 100644 test/jdk/tools/launcher/modules/illegalaccess/TryAccess.java
delete mode 100644 test/jdk/tools/launcher/modules/illegalaccess/modules/m/module-info.java
delete mode 100644 test/jdk/tools/launcher/modules/illegalaccess/modules/m/p/Type.java
delete mode 100644 test/jdk/tools/launcher/modules/illegalaccess/patchsrc/java.base/java/lang/Helper.java
diff --git a/src/hotspot/share/runtime/arguments.cpp b/src/hotspot/share/runtime/arguments.cpp
index 49f9c74fb22..5d45fce4606 100644
--- a/src/hotspot/share/runtime/arguments.cpp
+++ b/src/hotspot/share/runtime/arguments.cpp
@@ -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))) {
diff --git a/src/java.base/share/classes/java/lang/Module.java b/src/java.base/share/classes/java/lang/Module.java
index c4ce97dd26d..a0c034888f6 100644
--- a/src/java.base/share/classes/java/lang/Module.java
+++ b/src/java.base/share/classes/java/lang/Module.java
@@ -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)) {
diff --git a/src/java.base/share/classes/java/lang/invoke/MethodHandles.java b/src/java.base/share/classes/java/lang/invoke/MethodHandles.java
index b89dcef0cb0..a460ae7f262 100644
--- a/src/java.base/share/classes/java/lang/invoke/MethodHandles.java
+++ b/src/java.base/share/classes/java/lang/invoke/MethodHandles.java
@@ -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);
}
diff --git a/src/java.base/share/classes/java/lang/reflect/AccessibleObject.java b/src/java.base/share/classes/java/lang/reflect/AccessibleObject.java
index 3cd583b31d8..e87b431ec5c 100644
--- a/src/java.base/share/classes/java/lang/reflect/AccessibleObject.java
+++ b/src/java.base/share/classes/java/lang/reflect/AccessibleObject.java
@@ -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,7 +323,6 @@ private boolean checkCanSetAccessible(Class<?> caller,
if (isClassPublic && declaringModule.isExported(pn, callerModule)) {
// member is public
if (Modifier.isPublic(modifiers)) {
- logIfExportedForIllegalAccess(caller, declaringClass);
return true;
}
@@ -332,14 +330,12 @@ private boolean checkCanSetAccessible(Class<?> caller,
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)
diff --git a/src/java.base/share/classes/jdk/internal/module/ExplodedSystemModules.java b/src/java.base/share/classes/jdk/internal/module/ExplodedSystemModules.java
index 5f241913e70..c276647e3b1 100644
--- a/src/java.base/share/classes/jdk/internal/module/ExplodedSystemModules.java
+++ b/src/java.base/share/classes/jdk/internal/module/ExplodedSystemModules.java
@@ -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();
- }
}
diff --git a/src/java.base/share/classes/jdk/internal/module/IllegalAccessLogger.java b/src/java.base/share/classes/jdk/internal/module/IllegalAccessLogger.java
deleted file mode 100644
index ebbcffd77d9..00000000000
--- a/src/java.base/share/classes/jdk/internal/module/IllegalAccessLogger.java
+++ /dev/null
@@ -1,407 +0,0 @@
-/*
- * Copyright (c) 2017, 2020, 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
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation. Oracle designates this
- * particular file as subject to the "Classpath" exception as provided
- * by Oracle in the LICENSE file that accompanied this code.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-
-package jdk.internal.module;
-
-import java.io.PrintStream;
-import java.lang.invoke.MethodHandles;
-import java.net.URL;
-import java.security.AccessController;
-import java.security.CodeSource;
-import java.security.PrivilegedAction;
-import java.security.ProtectionDomain;
-import java.util.HashMap;
-import java.util.LinkedHashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Objects;
-import java.util.Set;
-import java.util.StringJoiner;
-import java.util.WeakHashMap;
-import java.util.function.Supplier;
-import static java.util.Collections.*;
-
-import jdk.internal.access.JavaLangAccess;
-import jdk.internal.access.SharedSecrets;
-
-/**
- * Supports logging of access to members of exported and concealed packages
- * that are opened to code in unnamed modules for illegal access.
- */
-
-public final class IllegalAccessLogger {
-
- /**
- * Logger modes
- */
- public enum Mode {
- /**
- * Prints a warning when an illegal access succeeds and then
- * discards the logger so that there is no further output.
- */
- ONESHOT,
- /**
- * Print warnings when illegal access succeeds
- */
- WARN,
- /**
- * Prints warnings and a stack trace when illegal access succeeds
- */
- DEBUG,
- }
-
- /**
- * A builder for IllegalAccessLogger objects.
- */
- public static class Builder {
- private final Mode mode;
- private final PrintStream warningStream;
- private final Map<Module, Set<String>> moduleToConcealedPackages;
- private final Map<Module, Set<String>> moduleToExportedPackages;
- private boolean complete;
-
- private void ensureNotComplete() {
- if (complete) throw new IllegalStateException();
- }
-
- /**
- * Creates a builder.
- */
- public Builder(Mode mode, PrintStream warningStream) {
- this.mode = mode;
- this.warningStream = warningStream;
- this.moduleToConcealedPackages = new HashMap<>();
- this.moduleToExportedPackages = new HashMap<>();
- }
-
- /**
- * Adding logging of reflective-access to any member of a type in
- * otherwise concealed packages.
- */
- public Builder logAccessToConcealedPackages(Module m, Set<String> packages) {
- ensureNotComplete();
- moduleToConcealedPackages.put(m, unmodifiableSet(packages));
- return this;
- }
-
- /**
- * Adding logging of reflective-access to non-public members/types in
- * otherwise exported (not open) packages.
- */
- public Builder logAccessToExportedPackages(Module m, Set<String> packages) {
- ensureNotComplete();
- moduleToExportedPackages.put(m, unmodifiableSet(packages));
- return this;
- }
-
- /**
- * Builds the IllegalAccessLogger and sets it as the system-wide logger.
- */
- public void complete() {
- Map<Module, Set<String>> map1 = unmodifiableMap(moduleToConcealedPackages);
- Map<Module, Set<String>> map2 = unmodifiableMap(moduleToExportedPackages);
- logger = new IllegalAccessLogger(mode, warningStream, map1, map2);
- complete = true;
- }
- }
-
- // need access to java.lang.Module
- private static final JavaLangAccess JLA = SharedSecrets.getJavaLangAccess();
-
- // system-wide IllegalAccessLogger
- private static volatile IllegalAccessLogger logger;
-
- // logger mode
- private final Mode mode;
-
- // the print stream to send the warnings
- private final PrintStream warningStream;
-
- // module -> packages open for illegal access
- private final Map<Module, Set<String>> moduleToConcealedPackages;
- private final Map<Module, Set<String>> moduleToExportedPackages;
-
- // caller -> usages
- private final Map<Class<?>, Usages> callerToUsages = new WeakHashMap<>();
-
- private IllegalAccessLogger(Mode mode,
- PrintStream warningStream,
- Map<Module, Set<String>> moduleToConcealedPackages,
- Map<Module, Set<String>> moduleToExportedPackages)
- {
- this.mode = mode;
- this.warningStream = warningStream;
- this.moduleToConcealedPackages = moduleToConcealedPackages;
- this.moduleToExportedPackages = moduleToExportedPackages;
- }
-
- /**
- * Returns the system-wide IllegalAccessLogger or {@code null} if there is
- * no logger.
- */
- public static IllegalAccessLogger illegalAccessLogger() {
- return logger;
- }
-
- /**
- * Returns true if the module exports a concealed package for illegal
- * access.
- */
- public boolean isExportedForIllegalAccess(Module module, String pn) {
- Set<String> packages = moduleToConcealedPackages.get(module);
- if (packages != null && packages.contains(pn))
- return true;
- return false;
- }
-
- /**
- * Returns true if the module opens a concealed or exported package for
- * illegal access.
- */
- public boolean isOpenForIllegalAccess(Module module, String pn) {
- if (isExportedForIllegalAccess(module, pn))
- return true;
- Set<String> packages = moduleToExportedPackages.get(module);
- if (packages != null && packages.contains(pn))
- return true;
- return false;
- }
-
- /**
- * Logs access to the member of a target class by a caller class if the class
- * is in a package that is exported for illegal access.
- *
- * The {@code whatSupplier} supplies the message that describes the member.
- */
- public void logIfExportedForIllegalAccess(Class<?> caller,
- Class<?> target,
- Supplier<String> whatSupplier) {
- Module targetModule = target.getModule();
- String targetPackage = target.getPackageName();
- if (isExportedForIllegalAccess(targetModule, targetPackage)) {
- Module callerModule = caller.getModule();
- if (!JLA.isReflectivelyExported(targetModule, targetPackage, callerModule)) {
- log(caller, whatSupplier.get());
- }
- }
- }
-
- /**
- * Logs access to the member of a target class by a caller class if the class
- * is in a package that is opened for illegal access.
- *
- * The {@code what} parameter supplies the message that describes the member.
- */
- public void logIfOpenedForIllegalAccess(Class<?> caller,
- Class<?> target,
- Supplier<String> whatSupplier) {
- Module targetModule = target.getModule();
- String targetPackage = target.getPackageName();
- if (isOpenForIllegalAccess(targetModule, targetPackage)) {
- Module callerModule = caller.getModule();
- if (!JLA.isReflectivelyOpened(targetModule, targetPackage, callerModule)) {
- log(caller, whatSupplier.get());
- }
- }
- }
-
- /**
- * Logs access by caller lookup if the target class is in a package that is
- * opened for illegal access.
- */
- public void logIfOpenedForIllegalAccess(MethodHandles.Lookup caller, Class<?> target) {
- Module targetModule = target.getModule();
- String targetPackage = target.getPackageName();
- if (isOpenForIllegalAccess(targetModule, targetPackage)) {
- Class<?> callerClass = caller.lookupClass();
- Module callerModule = callerClass.getModule();
- if (!JLA.isReflectivelyOpened(targetModule, targetPackage, callerModule)) {
- URL url = codeSource(callerClass);
- final String source;
- if (url == null) {
- source = callerClass.getName();
- } else {
- source = callerClass.getName() + " (" + url + ")";
- }
- log(callerClass, target.getName(), () ->
- "WARNING: Illegal reflective access using Lookup on " + source
- + " to " + target);
- }
- }
- }
-
- /**
- * Logs access by a caller class. The {@code what} parameter describes
- * the member being accessed.
- */
- private void log(Class<?> caller, String what) {
- log(caller, what, () -> {
- URL url = codeSource(caller);
- String source = caller.getName();
- if (url != null)
- source += " (" + url + ")";
- return "WARNING: Illegal reflective access by " + source + " to " + what;
- });
- }
-
- /**
- * Log access by a caller. The {@code what} parameter describes the class or
- * member that is being accessed. The {@code msgSupplier} supplies the log
- * message.
- *
- * To reduce output, this method only logs the access if it hasn't been seen
- * previously. "Seen previously" is implemented as a map of caller class -> Usage,
- * where a Usage is the "what" and a hash of the stack trace. The map has weak
- * keys so it can be expunged when the caller is GC'ed/unloaded.
- */
- private void log(Class<?> caller, String what, Supplier<String> msgSupplier) {
- if (mode == Mode.ONESHOT) {
- synchronized (IllegalAccessLogger.class) {
- // discard the system wide logger
- if (logger == null)
- return;
- logger = null;
- }
- warningStream.println(loudWarning(caller, msgSupplier));
- return;
- }
-
- // stack trace without the top-most frames in java.base
- List<StackWalker.StackFrame> stack = StackWalkerHolder.INSTANCE.walk(s ->
- s.dropWhile(this::isJavaBase)
- .limit(32)
- .toList()
- );
-
- // record usage if this is the first (or not recently recorded)
- Usage u = new Usage(what, hash(stack));
- boolean added;
- synchronized (this) {
- added = callerToUsages.computeIfAbsent(caller, k -> new Usages()).add(u);
- }
-
- // print warning if this is the first (or not a recent) usage
- if (added) {
- String msg = msgSupplier.get();
- if (mode == Mode.DEBUG) {
- StringBuilder sb = new StringBuilder(msg);
- stack.forEach(f ->
- sb.append(System.lineSeparator()).append("\tat " + f)
- );
- msg = sb.toString();
- }
- warningStream.println(msg);
- }
- }
-
- /**
- * Returns the code source for the given class or null if there is no code source
- */
- private URL codeSource(Class<?> clazz) {
- PrivilegedAction<ProtectionDomain> pa = clazz::getProtectionDomain;
- CodeSource cs = AccessController.doPrivileged(pa).getCodeSource();
- return (cs != null) ? cs.getLocation() : null;
- }
-
- private String loudWarning(Class<?> caller, Supplier<String> msgSupplier) {
- StringJoiner sj = new StringJoiner(System.lineSeparator());
- sj.add("WARNING: An illegal reflective access operation has occurred");
- sj.add(msgSupplier.get());
- sj.add("WARNING: Please consider reporting this to the maintainers of "
- + caller.getName());
- sj.add("WARNING: Use --illegal-access=warn to enable warnings of further"
- + " illegal reflective access operations");
- sj.add("WARNING: All illegal access operations will be denied in a"
- + " future release");
- return sj.toString();
- }
-
- private static class StackWalkerHolder {
- static final StackWalker INSTANCE;
- static {
- PrivilegedAction<StackWalker> pa = () ->
- StackWalker.getInstance(StackWalker.Option.RETAIN_CLASS_REFERENCE);
- INSTANCE = AccessController.doPrivileged(pa);
- }
- }
-
- /**
- * Returns true if the stack frame is for a class in java.base.
- */
- private boolean isJavaBase(StackWalker.StackFrame frame) {
- Module caller = frame.getDeclaringClass().getModule();
- return "java.base".equals(caller.getName());
- }
-
- /**
- * Computes a hash code for the give stack frames. The hash code is based
- * on the class, method name, and BCI.
- */
- private int hash(List<StackWalker.StackFrame> stack) {
- int hash = 0;
- for (StackWalker.StackFrame frame : stack) {
- hash = (31 * hash) + Objects.hash(frame.getDeclaringClass(),
- frame.getMethodName(),
- frame.getByteCodeIndex());
- }
- return hash;
- }
-
- private static class Usage {
- private final String what;
- private final int stack;
- Usage(String what, int stack) {
- this.what = what;
- this.stack = stack;
- }
- @Override
- public int hashCode() {
- return what.hashCode() ^ stack;
- }
- @Override
- public boolean equals(Object ob) {
- if (ob instanceof Usage) {
- Usage that = (Usage)ob;
- return what.equals(that.what) && stack == (that.stack);
- } else {
- return false;
- }
- }
- }
-
- @SuppressWarnings("serial")
- private static class Usages extends LinkedHashMap<Usage, Boolean> {
- Usages() { }
- boolean add(Usage u) {
- return (putIfAbsent(u, Boolean.TRUE) == null);
- }
- @Override
- protected boolean removeEldestEntry(Map.Entry<Usage, Boolean> oldest) {
- // prevent map growing too big, say where a utility class
- // is used by generated code to do illegal access
- return size() > 16;
- }
- }
-}
diff --git a/src/java.base/share/classes/jdk/internal/module/IllegalAccessMaps.java b/src/java.base/share/classes/jdk/internal/module/IllegalAccessMaps.java
deleted file mode 100644
index bec2841af83..00000000000
--- a/src/java.base/share/classes/jdk/internal/module/IllegalAccessMaps.java
+++ /dev/null
@@ -1,130 +0,0 @@
-/*
- * Copyright (c) 2017, 2019, 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
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation. Oracle designates this
- * particular file as subject to the "Classpath" exception as provided
- * by Oracle in the LICENSE file that accompanied this code.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-package jdk.internal.module;
-
-import sun.nio.cs.UTF_8;
-
-import java.io.BufferedReader;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.io.UncheckedIOException;
-import java.lang.module.ModuleDescriptor;
-import java.lang.module.ModuleFinder;
-import java.lang.module.ModuleReference;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Map;
-import java.util.Set;
-
-/**
- * Generates the maps of concealed and exported packages to open at run-time.
- *
- * This is used at run-time for exploded builds, and at link-time to generate
- * the maps for the system modules in the run-time image.
- */
-
-public class IllegalAccessMaps {
- private final Map<String, Set<String>> concealedPackagesToOpen;
- private final Map<String, Set<String>> exportedPackagesToOpen;
-
- private IllegalAccessMaps(Map<String, Set<String>> map1,
- Map<String, Set<String>> map2) {
- this.concealedPackagesToOpen = map1;
- this.exportedPackagesToOpen = map2;
- }
-
- /**
- * Returns the map of concealed packages to open. The map key is the
- * module name, the value is the set of concealed packages to open.
- */
- public Map<String, Set<String>> concealedPackagesToOpen() {
- return concealedPackagesToOpen;
- }
-
- /**
- * Returns the map of exported packages to open. The map key is the
- * module name, the value is the set of exported packages to open.
- */
- public Map<String, Set<String>> exportedPackagesToOpen() {
- return exportedPackagesToOpen;
- }
-
- /**
- * Generate the maps of module to concealed and exported packages for
- * the system modules that are observable with the given module finder.
- */
- public static IllegalAccessMaps generate(ModuleFinder finder) {
- Map<String, ModuleDescriptor> map = new HashMap<>();
- finder.findAll().stream()
- .map(ModuleReference::descriptor)
- .forEach(md -> md.packages().forEach(pn -> map.putIfAbsent(pn, md)));
-
- Map<String, Set<String>> concealedPackagesToOpen = new HashMap<>();
- Map<String, Set<String>> exportedPackagesToOpen = new HashMap<>();
-
- String rn = "jdk8_packages.dat";
- InputStream in = IllegalAccessMaps.class.getResourceAsStream(rn);
- if (in == null) {
- throw new InternalError(rn + " not found");
- }
- try (BufferedReader br = new BufferedReader(
- new InputStreamReader(in, UTF_8.INSTANCE)))
- {
- br.lines()
- .filter(line -> !line.isEmpty() && !line.startsWith("#"))
- .forEach(pn -> {
- ModuleDescriptor descriptor = map.get(pn);
- if (descriptor != null && !isOpen(descriptor, pn)) {
- String name = descriptor.name();
- if (isExported(descriptor, pn)) {
- exportedPackagesToOpen.computeIfAbsent(name,
- k -> new HashSet<>()).add(pn);
- } else {
- concealedPackagesToOpen.computeIfAbsent(name,
- k -> new HashSet<>()).add(pn);
- }
- }
- });
-
- } catch (IOException ioe) {
- throw new UncheckedIOException(ioe);
- }
-
- return new IllegalAccessMaps(concealedPackagesToOpen, exportedPackagesToOpen);
- }
-
- private static boolean isExported(ModuleDescriptor descriptor, String pn) {
- return descriptor.exports()
- .stream()
- .anyMatch(e -> e.source().equals(pn) && !e.isQualified());
- }
-
- private static boolean isOpen(ModuleDescriptor descriptor, String pn) {
- return descriptor.opens()
- .stream()
- .anyMatch(e -> e.source().equals(pn) && !e.isQualified());
- }
-}
diff --git a/src/java.base/share/classes/jdk/internal/module/ModuleBootstrap.java b/src/java.base/share/classes/jdk/internal/module/ModuleBootstrap.java
index 013dec42976..b6b3dd7f086 100644
--- a/src/java.base/share/classes/jdk/internal/module/ModuleBootstrap.java
+++ b/src/java.base/share/classes/jdk/internal/module/ModuleBootstrap.java
@@ -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
@@ -38,7 +38,6 @@
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
-import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
@@ -147,8 +146,7 @@ private static boolean canUseArchivedBootLayer() {
getProperty("jdk.module.limitmods") == null && // --limit-modules
getProperty("jdk.module.addreads.0") == null && // --add-reads
getProperty("jdk.module.addexports.0") == null && // --add-exports
- getProperty("jdk.module.addopens.0") == null && // --add-opens
- getProperty("jdk.module.illegalAccess") == null; // --illegal-access
+ getProperty("jdk.module.addopens.0") == null; // --add-opens
}
/**
@@ -189,7 +187,6 @@ private static ModuleLayer boot2() {
String mainModule = System.getProperty("jdk.module.main");
Set<String> addModules = addModules();
Set<String> limitModules = limitModules();
- String illegalAccess = getAndRemoveProperty("jdk.module.illegalAccess");
PrintStream traceOutput = null;
String trace = getAndRemoveProperty("jdk.module.showModuleResolution");
@@ -221,8 +218,7 @@ private static ModuleLayer boot2() {
&& !haveModulePath
&& addModules.isEmpty()
&& limitModules.isEmpty()
- && !isPatched
- && illegalAccess == null) {
+ && !isPatched) {
systemModuleFinder = archivedModuleGraph.finder();
hasSplitPackages = archivedModuleGraph.hasSplitPackages();
hasIncubatorModules = archivedModuleGraph.hasIncubatorModules();
@@ -455,19 +451,10 @@ private static ModuleLayer boot2() {
checkIncubatingStatus(cf);
}
- // --add-reads, --add-exports/--add-opens, and --illegal-access
+ // --add-reads, --add-exports/--add-opens
addExtraReads(bootLayer);
boolean extraExportsOrOpens = addExtraExportsAndOpens(bootLayer);
- if (illegalAccess != null) {
- assert systemModules != null;
- addIllegalAccess(illegalAccess,
- systemModules,
- upgradeModulePath,
- bootLayer,
- extraExportsOrOpens);
- }
-
Counters.add("jdk.module.boot.7.adjustModulesTime");
// save module finders for later use
@@ -779,96 +766,6 @@ private static void addExtraExportsOrOpens(ModuleLayer bootLayer,
}
}
- /**
- * Process the --illegal-access option to open packages of system modules
- * in the boot layer to code in unnamed modules.
- */
- private static void addIllegalAccess(String illegalAccess,
- SystemModules systemModules,
- ModuleFinder upgradeModulePath,
- ModuleLayer bootLayer,
- boolean extraExportsOrOpens) {
-
- if (illegalAccess.equals("deny"))
- return; // nothing to do
-
- IllegalAccessLogger.Mode mode = switch (illegalAccess) {
- case "permit" -> IllegalAccessLogger.Mode.ONESHOT;
- case "warn" -> IllegalAccessLogger.Mode.WARN;
- case "debug" -> IllegalAccessLogger.Mode.DEBUG;
- default -> {
- fail("Value specified to --illegal-access not recognized:"
- + " '" + illegalAccess + "'");
- yield null;
- }
- };
-
- var builder = new IllegalAccessLogger.Builder(mode, System.err);
- Map<String, Set<String>> concealedPackagesToOpen = systemModules.concealedPackagesToOpen();
- Map<String, Set<String>> exportedPackagesToOpen = systemModules.exportedPackagesToOpen();
- if (concealedPackagesToOpen.isEmpty() && exportedPackagesToOpen.isEmpty()) {
- // need to generate (exploded build)
- IllegalAccessMaps maps = IllegalAccessMaps.generate(limitedFinder());
- concealedPackagesToOpen = maps.concealedPackagesToOpen();
- exportedPackagesToOpen = maps.exportedPackagesToOpen();
- }
-
- // open specific packages in the system modules
- Set<String> emptySet = Set.of();
- for (Module m : bootLayer.modules()) {
- ModuleDescriptor descriptor = m.getDescriptor();
- String name = m.getName();
-
- // skip open modules
- if (descriptor.isOpen()) {
- continue;
- }
-
- // skip modules loaded from the upgrade module path
- if (upgradeModulePath != null
- && upgradeModulePath.find(name).isPresent()) {
- continue;
- }
-
- Set<String> concealedPackages = concealedPackagesToOpen.getOrDefault(name, emptySet);
- Set<String> exportedPackages = exportedPackagesToOpen.getOrDefault(name, emptySet);
-
- // refresh the set of concealed and exported packages if needed
- if (extraExportsOrOpens) {
- concealedPackages = new HashSet<>(concealedPackages);
- exportedPackages = new HashSet<>(exportedPackages);
- Iterator<String> iterator = concealedPackages.iterator();
- while (iterator.hasNext()) {
- String pn = iterator.next();
- if (m.isExported(pn, BootLoader.getUnnamedModule())) {
- // concealed package is exported to ALL-UNNAMED
- iterator.remove();
- exportedPackages.add(pn);
- }
- }
- iterator = exportedPackages.iterator();
- while (iterator.hasNext()) {
- String pn = iterator.next();
- if (m.isOpen(pn, BootLoader.getUnnamedModule())) {
- // exported package is opened to ALL-UNNAMED
- iterator.remove();
- }
- }
- }
-
- // log reflective access to all types in concealed packages
- builder.logAccessToConcealedPackages(m, concealedPackages);
-
- // log reflective access to non-public members/types in exported packages
- builder.logAccessToExportedPackages(m, exportedPackages);
-
- // open the packages to unnamed modules
- JLA.addOpensToAllUnnamed(m, concealedPackages, exportedPackages);
- }
-
- builder.complete();
- }
-
/**
* Decodes the values of --add-reads, -add-exports, --add-opens or
* --patch-modules options that are encoded in system properties.
diff --git a/src/java.base/share/classes/jdk/internal/module/SystemModules.java b/src/java.base/share/classes/jdk/internal/module/SystemModules.java
index 8f6b8daa33c..4c74068acc8 100644
--- a/src/java.base/share/classes/jdk/internal/module/SystemModules.java
+++ b/src/java.base/share/classes/jdk/internal/module/SystemModules.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2015, 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
@@ -83,16 +83,4 @@
* by this SystemModules object.
*/
Map<String, Set<String>> moduleReads();
-
- /**
- * Returns the map of module concealed packages to open. The map key is the
- * module name, the value is the set of concealed packages to open.
- */
- Map<String, Set<String>> concealedPackagesToOpen();
-
- /**
- * Returns the map of module exported packages to open. The map key is the
- * module name, the value is the set of exported packages to open.
- */
- Map<String, Set<String>> exportedPackagesToOpen();
}