Path: blob/master/test/hotspot/jtreg/serviceability/jvmti/AddModuleUsesAndProvides/MyPackage/AddModuleUsesAndProvidesTest.java
41161 views
/*1* Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223package MyPackage;2425/**26* @test27* @summary Basic test for JVMTI AddModuleUses and AddModuleProvides28* @requires vm.jvmti29* @build java.base/java.lang.TestProvider30* java.base/jdk.internal.test.TestProviderImpl31* @compile AddModuleUsesAndProvidesTest.java32* @run main/othervm/native -agentlib:AddModuleUsesAndProvidesTest MyPackage.AddModuleUsesAndProvidesTest33*/3435import java.io.PrintStream;36import java.lang.TestProvider;3738public class AddModuleUsesAndProvidesTest {3940static {41try {42System.loadLibrary("AddModuleUsesAndProvidesTest");43} catch (UnsatisfiedLinkError ule) {44System.err.println("Could not load AddModuleUsesAndProvidesTest library");45System.err.println("java.library.path: "46+ System.getProperty("java.library.path"));47throw ule;48}49}5051native static int checkUses(Module baseModule, Class<?> service);52native static int checkProvides(Module baseModule, Class<?> service, Class<?> serviceImpl);5354public static void main(String args[]) throws Exception {55Module baseModule = Object.class.getModule();56Class<?> service = TestProvider.class;57Class<?> serviceImpl = Class.forName("jdk.internal.test.TestProviderImpl");5859System.out.println("\n*** Checks for JVMTI AddModuleUses ***\n");6061int status = checkUses(baseModule, service);62if (status != 0) {63throw new RuntimeException("Non-zero status returned from the agent: " + status);64}6566System.out.println("\n*** Checks for JVMTI AddModuleProvides ***\n");6768System.out.println("Check #PC1:");69if (TestProvider.providers().iterator().hasNext()) {70throw new RuntimeException("Check #PC1: Unexpectedly service is provided");71}7273status = checkProvides(baseModule, service, serviceImpl);74if (status != 0) {75throw new RuntimeException("Non-zero status returned from the agent: " + status);76}7778System.out.println("Check #PC3:");79if (!TestProvider.providers().iterator().hasNext()) {80throw new RuntimeException("Check #PC3: Unexpectedly service is not provided");81}82}83}848586