hotspot/test/runtime/modules/AccessCheck/p3/c3ReadEdgeDiffLoader.jcod
changeset 43665 4bb003cad9b9
parent 36508 5f9eee6b383b
child 44520 0553e129e0ec
equal deleted inserted replaced
43606:a5aa7536131c 43665:4bb003cad9b9
     1 /*
     1 /*
     2  * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
     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.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     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
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.
     7  * published by the Free Software Foundation.
    26  * import java.lang.reflect.*;
    26  * import java.lang.reflect.*;
    27  * import myloaders.MyDiffClassLoader;
    27  * import myloaders.MyDiffClassLoader;
    28  *
    28  *
    29  * public class c3ReadEdgeDiffLoader {
    29  * public class c3ReadEdgeDiffLoader {
    30  *    public c3ReadEdgeDiffLoader() {
    30  *    public c3ReadEdgeDiffLoader() {
    31  *       // The goal is to establish a read edge between module m1
    31  *       // The goal is to establish a read edge between module m1x
    32  *       // which is the module where p3.c3ReadEdgeDiffLoader is defined,
    32  *       // which is the module where p3.c3ReadEdgeDiffLoader is defined,
    33  *       // and the unnamed module that defines c4.  This must be
    33  *       // and the unnamed module that defines c4.  This must be
    34  *       // done in 2 steps:
    34  *       // done in 2 steps:
    35  *       //
    35  *       //
    36  *       // Step #1: Establish a read edge between m1, where c3ReadEdgeDiffLoader
    36  *       // Step #1: Establish a read edge between m1x, where c3ReadEdgeDiffLoader
    37  *       //          is defined, and the System ClassLoader's unnamed module,
    37  *       //          is defined, and the System ClassLoader's unnamed module,
    38  *       //          where MyDiffClassLoader is defined. This read edge
    38  *       //          where MyDiffClassLoader is defined. This read edge
    39  *       //          is needed before we can obtain MyDiffClassLoader.loader2's unnamed module.
    39  *       //          is needed before we can obtain MyDiffClassLoader.loader2's unnamed module.
    40  *       //
    40  *       //
    41  *       // Step #2: Establish a read edge between m1, where c3ReadEdgeDiffLoader
    41  *       // Step #2: Establish a read edge between m1x, where c3ReadEdgeDiffLoader
    42  *       //          is defined, and the MyDiffClassLoader.loader2's unnamed module,
    42  *       //          is defined, and the MyDiffClassLoader.loader2's unnamed module,
    43  *       //          where c4 will be defined.
    43  *       //          where c4 will be defined.
    44  *
    44  *
    45  *       // Step #1: read edge m1 -> System ClassLoader's unnamed module
    45  *       // Step #1: read edge m1x -> System ClassLoader's unnamed module
    46  *       Module m1 = c3ReadEdgeDiffLoader.class.getModule();
    46  *       Module m1x = c3ReadEdgeDiffLoader.class.getModule();
    47  *       ClassLoader system_loader = ClassLoader.getSystemClassLoader();
    47  *       ClassLoader system_loader = ClassLoader.getSystemClassLoader();
    48  *       Module unnamed_module1 = system_loader.getUnnamedModule();
    48  *       Module unnamed_module_one = system_loader.getUnnamedModule();
    49  *       m1.addReads(unnamed_module1);
    49  *       m1x.addReads(unnamed_module_one);
    50  *
    50  *
    51  *       // Step #2: read edge m1 -> MyDiffClassLoader.loader2's unnamed module
    51  *       // Step #2: read edge m1x -> MyDiffClassLoader.loader2's unnamed module
    52  *       ClassLoader loader2 = MyDiffClassLoader.loader2;
    52  *       ClassLoader loader2 = MyDiffClassLoader.loader2;
    53  *       Module unnamed_module2 = loader2.getUnnamedModule();
    53  *       Module unnamed_module_two = loader2.getUnnamedModule();
    54  *       m1.addReads(unnamed_module2);
    54  *       m1x.addReads(unnamed_module_two);
    55  *
    55  *
    56  *       // Attempt access - should succeed since m1 can read
    56  *       // Attempt access - should succeed since m1x can read
    57  *       //                  MyDiffClassLoader.loader2's unnamed module
    57  *       //                  MyDiffClassLoader.loader2's unnamed module
    58  *       c4 c4_obj = new c4();
    58  *       c4 c4_obj = new c4();
    59  *       c4_obj.method4();
    59  *       c4_obj.method4();
    60  *   }
    60  *   }
    61  * }
    61  * }