< prev index next >

test/hotspot/jtreg/runtime/getSysPackage/GetSysPkgTest.java

Print this page


   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 
  24 /*
  25  * @test
  26  * @modules java.base/jdk.internal.misc
  27  * @modules java.base/jdk.internal.loader
  28  *          java.desktop
  29  * @library /test/lib
  30  * @run main/othervm GetSysPkgTest
  31  */
  32 
  33 import java.io.File;
  34 import java.lang.reflect.InvocationTargetException;
  35 import java.lang.reflect.Method;
  36 import jdk.test.lib.compiler.InMemoryJavaCompiler;
  37 import jdk.test.lib.process.ProcessTools;
  38 import jdk.test.lib.process.OutputAnalyzer;
  39 
  40 // Test that JVM get_system_package() returns the module location for defined packages.
  41 public class GetSysPkgTest {
  42 
  43     private static Object invoke(Method m, Object obj, Object... args) throws Throwable {
  44         try {
  45             return m.invoke(obj, args);
  46         } catch (InvocationTargetException e) {
  47             throw e.getCause();
  48         }


 117         getPkg("com/sun/crypto/provider", null);
 118         // Now make sure a class in the package is referenced.
 119         Class newClass = Class.forName("com.sun.crypto.provider.PrivateKeyInfo");
 120         getPkg("com/sun/crypto/provider", "jrt:/java.base");
 121 
 122         getPkg("java/nio/charset", "jrt:/java.base");
 123 
 124         // Test a package in a module not owned by boot loader.
 125         Class clss = Class.forName("jdk.nio.zipfs.ZipPath");
 126         if (clss == null)
 127             throw new RuntimeException("Could not find class jdk.nio.zipfs.ZipPath");
 128         getPkg("javax/activation", null);       // Not owned by boot loader
 129 
 130         // Test a package not in jimage file.
 131         clss = Class.forName("GetSysPkg_package.GetSysClass");
 132         if (clss == null)
 133             throw new RuntimeException("Could not find class GetSysPkg_package.GetSysClass");
 134         getPkg("GetSysPkg_package", null);
 135 
 136         // Access a class with a package in a boot loader module other than java.base
 137         clss = Class.forName("java.awt.Button");

 138         if (clss == null)
 139             throw new RuntimeException("Could not find class java.awt.Button");
 140         getPkg("java/awt", "jrt:/java.desktop");
 141 
 142         // Test getting the package location from a class found via -Xbootclasspath/a
 143         clss = Class.forName("BootLdr_package.BootLdrPkg");
 144         if (clss == null)
 145             throw new RuntimeException("Could not find class BootLdr_package.BootLdrPkg");
 146         String bootldrPkg = (String)invoke(findMethod("getSystemPackageLocation"), null, "BootLdr_package");
 147         if (bootldrPkg == null) {
 148             throw new RuntimeException("Expected BootLdr_package to return non-null value");
 149         }
 150         if (!bootldrPkg.equals("bl_dir")) {
 151             throw new RuntimeException("Expected BootLdr_package to return bl_dir, got: " + bootldrPkg);
 152         }
 153 
 154         // Test when package's class reference is an array.
 155         // Note: if another class in javax/crypto happens to get loaded
 156         //       or if class AEADBadTagException disappears from this package
 157         //       then this test will fail.
 158         getPkg("javax/crypto", null);
 159         javax.crypto.AEADBadTagException[] blah = new javax.crypto.AEADBadTagException[3];
 160         getPkg("javax/crypto", "jrt:/java.base");


   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 
  24 /*
  25  * @test
  26  * @modules java.base/jdk.internal.misc
  27  * @modules java.base/jdk.internal.loader
  28  *          java.logging
  29  * @library /test/lib
  30  * @run main/othervm GetSysPkgTest
  31  */
  32 
  33 import java.io.File;
  34 import java.lang.reflect.InvocationTargetException;
  35 import java.lang.reflect.Method;
  36 import jdk.test.lib.compiler.InMemoryJavaCompiler;
  37 import jdk.test.lib.process.ProcessTools;
  38 import jdk.test.lib.process.OutputAnalyzer;
  39 
  40 // Test that JVM get_system_package() returns the module location for defined packages.
  41 public class GetSysPkgTest {
  42 
  43     private static Object invoke(Method m, Object obj, Object... args) throws Throwable {
  44         try {
  45             return m.invoke(obj, args);
  46         } catch (InvocationTargetException e) {
  47             throw e.getCause();
  48         }


 117         getPkg("com/sun/crypto/provider", null);
 118         // Now make sure a class in the package is referenced.
 119         Class newClass = Class.forName("com.sun.crypto.provider.PrivateKeyInfo");
 120         getPkg("com/sun/crypto/provider", "jrt:/java.base");
 121 
 122         getPkg("java/nio/charset", "jrt:/java.base");
 123 
 124         // Test a package in a module not owned by boot loader.
 125         Class clss = Class.forName("jdk.nio.zipfs.ZipPath");
 126         if (clss == null)
 127             throw new RuntimeException("Could not find class jdk.nio.zipfs.ZipPath");
 128         getPkg("javax/activation", null);       // Not owned by boot loader
 129 
 130         // Test a package not in jimage file.
 131         clss = Class.forName("GetSysPkg_package.GetSysClass");
 132         if (clss == null)
 133             throw new RuntimeException("Could not find class GetSysPkg_package.GetSysClass");
 134         getPkg("GetSysPkg_package", null);
 135 
 136         // Access a class with a package in a boot loader module other than java.base
 137         clss = Class.forName("java.util.logging.Level");
 138 
 139         if (clss == null)
 140             throw new RuntimeException("Could not find class java.util.logging.Level");
 141         getPkg("java/util/logging", "jrt:/java.logging");
 142 
 143         // Test getting the package location from a class found via -Xbootclasspath/a
 144         clss = Class.forName("BootLdr_package.BootLdrPkg");
 145         if (clss == null)
 146             throw new RuntimeException("Could not find class BootLdr_package.BootLdrPkg");
 147         String bootldrPkg = (String)invoke(findMethod("getSystemPackageLocation"), null, "BootLdr_package");
 148         if (bootldrPkg == null) {
 149             throw new RuntimeException("Expected BootLdr_package to return non-null value");
 150         }
 151         if (!bootldrPkg.equals("bl_dir")) {
 152             throw new RuntimeException("Expected BootLdr_package to return bl_dir, got: " + bootldrPkg);
 153         }
 154 
 155         // Test when package's class reference is an array.
 156         // Note: if another class in javax/crypto happens to get loaded
 157         //       or if class AEADBadTagException disappears from this package
 158         //       then this test will fail.
 159         getPkg("javax/crypto", null);
 160         javax.crypto.AEADBadTagException[] blah = new javax.crypto.AEADBadTagException[3];
 161         getPkg("javax/crypto", "jrt:/java.base");
< prev index next >