Path: blob/master/test/hotspot/jtreg/runtime/InvocationTests/shared/Caller.java
40948 views
/*1* Copyright (c) 2009, 2019, 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*22*/2324package shared;2526import java.lang.reflect.InvocationTargetException;2728/*******************************************************************/29// Invoke different target method callers30/*******************************************************************/3132public class Caller {33private ClassLoader loader;34private Class paramClass;35private Class targetClass;36private boolean passed = true;37private Checker checker;3839public Caller(ClassLoader loader, Checker checker,40Class paramClass, Class targetClass) {41this.loader = loader;42this.paramClass = paramClass;43this.targetClass = targetClass;44this.checker = checker;45}4647public boolean isPassed() {48return passed;49}5051public String call(String invoker) {52try {53Class clazz = loader.loadClass(invoker);5455String expectedBehavior = checker.check(clazz);5657String result = null;58Throwable exc = null;59try {60java.lang.reflect.Method m = clazz.getDeclaredMethod("call", paramClass);61result = (String) m.invoke(null, targetClass.newInstance());62} catch (InvocationTargetException e) {63exc = e.getCause();64} catch (Throwable e) {65exc = e;66}6768if (result == null) {69if (exc != null) {70result = exc.getClass().getName();71} else {72result = "null";73}74}7576if (!(result.equals(expectedBehavior) || "".equals(expectedBehavior)) ) {77passed = false;78result = String.format("%s/%s", result, expectedBehavior);79}8081return Checker.abbreviateResult(result);82} catch (Exception e) {83throw new RuntimeException(e);84}85}86}878889