author | alanb |
Fri, 10 Feb 2017 09:03:55 +0000 | |
changeset 43665 | 4bb003cad9b9 |
parent 36508 | 5f9eee6b383b |
child 44520 | 0553e129e0ec |
permissions | -rw-r--r-- |
36508 | 1 |
/* |
43665
4bb003cad9b9
8173393: Module system implementation refresh (2/2017)
alanb
parents:
36508
diff
changeset
|
2 |
* Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved. |
36508 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. |
|
8 |
* |
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
13 |
* accompanied this code). |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License version |
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
18 |
* |
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
20 |
* or visit www.oracle.com if you need additional information or have any |
|
21 |
* questions. |
|
22 |
*/ |
|
23 |
package p1; |
|
24 |
||
25 |
import java.lang.reflect.*; |
|
26 |
import myloaders.MyDiffClassLoader; |
|
27 |
import p2.c2; |
|
28 |
||
29 |
public class c1ReadEdgeDiffLoader { |
|
30 |
public c1ReadEdgeDiffLoader() { |
|
43665
4bb003cad9b9
8173393: Module system implementation refresh (2/2017)
alanb
parents:
36508
diff
changeset
|
31 |
// The goal is to establish a read edge between module m1x |
36508 | 32 |
// which is the module where p1.c1ReadEdgeDiffLoader is defined, |
33 |
// and the unnamed module that defines p2.c2. This must be |
|
34 |
// done in 2 steps: |
|
35 |
// |
|
43665
4bb003cad9b9
8173393: Module system implementation refresh (2/2017)
alanb
parents:
36508
diff
changeset
|
36 |
// Step #1: Establish a read edge between m1x, where c1ReadEdgeDiffLoader |
36508 | 37 |
// is defined, and the System ClassLoader's unnamed module, |
38 |
// where MyDiffClassLoader is defined. This read edge |
|
39 |
// is needed before we can obtain MyDiffClassLoader.loader2's unnamed module. |
|
40 |
// |
|
43665
4bb003cad9b9
8173393: Module system implementation refresh (2/2017)
alanb
parents:
36508
diff
changeset
|
41 |
// Step #2: Establish a read edge between m1x, where c1ReadEdgeDiffLoader |
36508 | 42 |
// is defined, and the MyDiffClassLoader.loader2's unnamed module, |
43 |
// where p2.c2 will be defined. |
|
44 |
||
43665
4bb003cad9b9
8173393: Module system implementation refresh (2/2017)
alanb
parents:
36508
diff
changeset
|
45 |
// Step #1: read edge m1x -> System ClassLoader's unnamed module |
4bb003cad9b9
8173393: Module system implementation refresh (2/2017)
alanb
parents:
36508
diff
changeset
|
46 |
Module m1x = c1ReadEdgeDiffLoader.class.getModule(); |
36508 | 47 |
ClassLoader system_loader = ClassLoader.getSystemClassLoader(); |
43665
4bb003cad9b9
8173393: Module system implementation refresh (2/2017)
alanb
parents:
36508
diff
changeset
|
48 |
Module unnamed_module_one = system_loader.getUnnamedModule(); |
4bb003cad9b9
8173393: Module system implementation refresh (2/2017)
alanb
parents:
36508
diff
changeset
|
49 |
m1x.addReads(unnamed_module_one); |
36508 | 50 |
|
43665
4bb003cad9b9
8173393: Module system implementation refresh (2/2017)
alanb
parents:
36508
diff
changeset
|
51 |
// Step #2: read edge m1x -> MyDiffClassLoader.loader2's unnamed module |
36508 | 52 |
ClassLoader loader2 = MyDiffClassLoader.loader2; |
43665
4bb003cad9b9
8173393: Module system implementation refresh (2/2017)
alanb
parents:
36508
diff
changeset
|
53 |
Module unnamed_module_two = loader2.getUnnamedModule(); |
4bb003cad9b9
8173393: Module system implementation refresh (2/2017)
alanb
parents:
36508
diff
changeset
|
54 |
m1x.addReads(unnamed_module_two); |
36508 | 55 |
|
43665
4bb003cad9b9
8173393: Module system implementation refresh (2/2017)
alanb
parents:
36508
diff
changeset
|
56 |
// Attempt access - access should succeed since m1x can read |
36508 | 57 |
// MyDiffClassLoader.loader2's unnamed module |
58 |
p2.c2 c2_obj = new p2.c2(); |
|
59 |
c2_obj.method2(); |
|
60 |
} |
|
61 |
} |