Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/com/sun/jdi/EvalInterfaceStatic.sh
38855 views
#!/bin/sh12#3# Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.4# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.5#6# This code is free software; you can redistribute it and/or modify it7# under the terms of the GNU General Public License version 2 only, as8# published by the Free Software Foundation.9#10# This code is distributed in the hope that it will be useful, but WITHOUT11# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13# version 2 for more details (a copy is included in the LICENSE file that14# accompanied this code).15#16# You should have received a copy of the GNU General Public License version17# 2 along with this work; if not, write to the Free Software Foundation,18# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19#20# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21# or visit www.oracle.com if you need additional information or have any22# questions.23#2425# @test26# @bug 803119527# @summary JDB allows evaluation of calls to static interface methods28# @author Jaroslav Bachorik29#30# @run shell/timeout=300 EvalInterfaceStatic.sh3132# The test exercises the ability to invoke static methods on interfaces.33# Static interface methods are a new feature added in JDK8.34#35# The test makes sure that it is, at all, possible to invoke an interface36# static method and that the static methods are not inherited by extending37# interfaces.3839classname=EvalStaticInterfaces4041createJavaFile()42{43cat <<EOF > $classname.java.144public interface $classname {45static String staticMethod1() {46return "base:staticMethod1";47}4849static String staticMethod2() {50return "base:staticMethod2";51}5253public static void main(String[] args) {54// prove that these work55System.out.println("base staticMethod1(): " + $classname.staticMethod1());56System.out.println("base staticMethod2(): " + $classname.staticMethod2());57System.out.println("overridden staticMethod2(): " + Extended$classname.staticMethod2());58System.out.println("base staticMethod3(): " + Extended$classname.staticMethod3());5960gus();61}6263static void gus() {64int x = 0; // @1 breakpoint65}66}6768interface Extended$classname extends $classname {69static String staticMethod2() {70return "extended:staticMethod2";71}7273static String staticMethod3() {74return "extended:staticMethod3";75}76}77787980EOF81}8283# drive jdb by sending cmds to it and examining its output84dojdbCmds()85{86setBkpts @187runToBkpt @18889cmd eval "$classname.staticMethod1()"90jdbFailIfNotPresent "base:staticMethod1" 29192cmd eval "$classname.staticMethod2()"93jdbFailIfNotPresent "base:staticMethod2" 29495cmd eval "Extended$classname.staticMethod1()"96jdbFailIfPresent "base:staticMethod1" 29798cmd eval "Extended$classname.staticMethod2()"99jdbFailIfNotPresent "extended:staticMethod2" 2100101cmd eval "Extended$classname.staticMethod3()"102jdbFailIfNotPresent "extended:staticMethod3" 2103}104105106mysetup()107{108if [ -z "$TESTSRC" ] ; then109TESTSRC=.110fi111112for ii in . $TESTSRC $TESTSRC/.. ; do113if [ -r "$ii/ShellScaffold.sh" ] ; then114. $ii/ShellScaffold.sh115break116fi117done118}119120# You could replace this next line with the contents121# of ShellScaffold.sh and this script will run just the same.122mysetup123124runit125pass126127128