jdk

Форк
0
/
c1ReadEdgeDiffLoader.java 
60 строк · 2.7 Кб
1
/*
2
 * Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved.
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 myloaders.MyDiffClassLoader;
26
import p2.c2;
27

28
public class c1ReadEdgeDiffLoader {
29
    public c1ReadEdgeDiffLoader() {
30
        // The goal is to establish a read edge between module m1x
31
        // which is the module where p1.c1ReadEdgeDiffLoader is defined,
32
        // and the unnamed module that defines p2.c2.  This must be
33
        // done in 2 steps:
34
        //
35
        // Step #1: Establish a read edge between m1x, where c1ReadEdgeDiffLoader
36
        //          is defined, and the System ClassLoader's unnamed module,
37
        //          where MyDiffClassLoader is defined. This read edge
38
        //          is needed before we can obtain MyDiffClassLoader.loader2's unnamed module.
39
        //
40
        // Step #2: Establish a read edge between m1x, where c1ReadEdgeDiffLoader
41
        //          is defined, and the MyDiffClassLoader.loader2's unnamed module,
42
        //          where p2.c2 will be defined.
43

44
        // Step #1: read edge m1x -> System ClassLoader's unnamed module
45
        Module m1x = c1ReadEdgeDiffLoader.class.getModule();
46
        ClassLoader system_loader = ClassLoader.getSystemClassLoader();
47
        Module unnamed_module_one = system_loader.getUnnamedModule();
48
        m1x.addReads(unnamed_module_one);
49

50
        // Step #2: read edge m1x -> MyDiffClassLoader.loader2's unnamed module
51
        ClassLoader loader2 = MyDiffClassLoader.loader2;
52
        Module unnamed_module_two = loader2.getUnnamedModule();
53
        m1x.addReads(unnamed_module_two);
54

55
        // Attempt access - access should succeed since m1x can read
56
        //                  MyDiffClassLoader.loader2's unnamed module
57
        p2.c2 c2_obj = new p2.c2();
58
        c2_obj.method2();
59
    }
60
}
61

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.