jdk/test/com/sun/jdi/InterfaceMethodsTest.java
author jbachorik
Tue, 29 Apr 2014 11:15:21 +0200
changeset 24125 b85eeaae56c7
child 24973 8c4bc3fa4c4e
permissions -rw-r--r--
8031195: Support default and static interface methods in JDI, JDWP and JDB Reviewed-by: sla, sspitsyn, dcubed
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
24125
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
     1
/*
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
     2
 * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
     4
 *
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
     7
 * published by the Free Software Foundation.
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
     8
 *
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
    13
 * accompanied this code).
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
    14
 *
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
    18
 *
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
    21
 * questions.
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
    22
 */
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
    23
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
    24
/**
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
    25
 *  @test
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
    26
 *  @bug 8031195
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
    27
 *  @summary  JDI: Add support for static and default methods in interfaces
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
    28
 *
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
    29
 *  @run build TestScaffold VMConnection TargetListener TargetAdapter
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
    30
 *  @run build InterfaceMethodsTest
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
    31
 *  @run main InterfaceMethodsTest
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
    32
 */
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
    33
import com.sun.jdi.*;
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
    34
import com.sun.jdi.event.*;
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
    35
import java.util.Collections;
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
    36
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
    37
public class InterfaceMethodsTest extends TestScaffold {
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
    38
    private static final int RESULT_A = 1;
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
    39
    private static final int RESULT_B = 1;
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
    40
    private static final int RESULT_TARGET = 1;
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
    41
    static interface InterfaceA {
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
    42
        static int staticMethodA() {
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
    43
            System.out.println("-InterfaceA: static interface method A-");
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
    44
            return RESULT_A;
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
    45
        }
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
    46
        static int staticMethodB() {
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
    47
            System.out.println("-InterfaceA: static interface method B-");
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
    48
            return RESULT_A;
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
    49
        }
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
    50
        default int defaultMethodA() {
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
    51
            System.out.println("-InterfaceA: default interface method A-");
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
    52
            return RESULT_A;
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
    53
        }
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
    54
        default int defaultMethodB() {
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
    55
            System.out.println("-InterfaceA: default interface method B-");
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
    56
            return RESULT_A;
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
    57
        }
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
    58
        default int defaultMethodC() {
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
    59
            System.out.println("-InterfaceA: default interface method C-");
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
    60
            return RESULT_A;
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
    61
        }
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
    62
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
    63
        int implementedMethod();
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
    64
    }
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
    65
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
    66
    static interface InterfaceB extends InterfaceA {
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
    67
        @Override
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
    68
        default int defaultMethodC() {
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
    69
            System.out.println("-InterfaceB: overridden default interface method C-");
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
    70
            return RESULT_B;
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
    71
        }
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
    72
        default int defaultMethodD() {
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
    73
            System.out.println("-InterfaceB: default interface method D-");
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
    74
            return RESULT_B;
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
    75
        }
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
    76
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
    77
        static int staticMethodB() {
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
    78
            System.out.println("-InterfaceB: overridden static interface method B-");
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
    79
            return RESULT_B;
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
    80
        }
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
    81
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
    82
        static int staticMethodC() {
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
    83
            System.out.println("-InterfaceB: static interface method C-");
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
    84
            return RESULT_B;
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
    85
        }
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
    86
    }
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
    87
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
    88
    final static class TargetClass implements InterfaceB {
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
    89
        public int classMethod() {
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
    90
            System.out.println("-TargetClass: class only method-");
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
    91
            return RESULT_TARGET;
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
    92
        }
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
    93
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
    94
        @Override
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
    95
        public int implementedMethod() {
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
    96
            System.out.println("-TargetClass: implemented non-default interface method-");
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
    97
            return RESULT_TARGET;
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
    98
        }
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
    99
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   100
        @Override
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   101
        public int defaultMethodB() {
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   102
            System.out.println("-TargetClass: overridden default interface method D");
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   103
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   104
            return RESULT_TARGET;
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   105
        }
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   106
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   107
        public static void main(String[] args) {
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   108
            TargetClass tc = new TargetClass();
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   109
            tc.doTests(tc);
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   110
        }
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   111
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   112
        private void doTests(TargetClass ref) {
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   113
            // break
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   114
        }
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   115
    }
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   116
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   117
    public InterfaceMethodsTest(String[] args) {
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   118
        super(args);
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   119
    }
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   120
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   121
    public static void main(String[] args) throws Exception {
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   122
        new InterfaceMethodsTest(args).startTests();
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   123
    }
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   124
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   125
    private static final String TEST_CLASS_NAME = InterfaceMethodsTest.class.getName().replace('.', '/');
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   126
    private static final String TARGET_CLASS_NAME = TargetClass.class.getName().replace('.', '/');
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   127
    private static final String INTERFACEA_NAME = InterfaceA.class.getName().replace('.', '/');
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   128
    private static final String INTERFACEB_NAME = InterfaceB.class.getName().replace('.', '/');
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   129
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   130
    protected void runTests() throws Exception {
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   131
        /*
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   132
         * Get to the top of main()
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   133
         * to determine targetClass and mainThread
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   134
         */
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   135
        BreakpointEvent bpe = startToMain(TARGET_CLASS_NAME);
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   136
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   137
        bpe = resumeTo(TARGET_CLASS_NAME, "doTests", "(L" + TARGET_CLASS_NAME +";)V");
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   138
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   139
        mainThread = bpe.thread();
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   140
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   141
        StackFrame frame = mainThread.frame(0);
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   142
        ObjectReference thisObject = frame.thisObject();
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   143
        ObjectReference ref = (ObjectReference)frame.getArgumentValues().get(0);
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   144
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   145
        ReferenceType targetClass = bpe.location().declaringType();
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   146
        testImplementationClass(targetClass, thisObject);
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   147
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   148
        testInterfaceA(ref);
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   149
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   150
        testInterfaceB(ref);
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   151
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   152
        /*
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   153
         * resume the target listening for events
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   154
         */
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   155
        listenUntilVMDisconnect();
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   156
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   157
        /*
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   158
         * deal with results of test
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   159
         * if anything has called failure("foo") testFailed will be true
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   160
         */
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   161
        if (!testFailed) {
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   162
            println("InterfaceMethodsTest: passed");
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   163
        } else {
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   164
            throw new Exception("InterfaceMethodsTest: failed");
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   165
        }
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   166
    }
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   167
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   168
    private void testInterfaceA(ObjectReference ref) {
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   169
        // Test non-virtual calls on InterfaceA
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   170
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   171
        ReferenceType ifaceClass = (ReferenceType)vm().classesByName(INTERFACEA_NAME).get(0);
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   172
        /* Default method calls */
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   173
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   174
        // invoke the InterfaceA's "defaultMethodA"
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   175
        testInvokePos(ifaceClass, ref, "defaultMethodA", "()I", vm().mirrorOf(RESULT_A));
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   176
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   177
        // invoke the InterfaceA's "defaultMethodB"
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   178
        testInvokePos(ifaceClass, ref, "defaultMethodB", "()I", vm().mirrorOf(RESULT_A));
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   179
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   180
        // invoke the InterfaceA's "defaultMethodC"
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   181
        testInvokePos(ifaceClass, ref, "defaultMethodC", "()I", vm().mirrorOf(RESULT_A));
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   182
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   183
        // "defaultMethodD" from InterfaceB is not accessible from here
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   184
        testInvokeNeg(ifaceClass, ref, "defaultMethodD", "()I", vm().mirrorOf(RESULT_B),
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   185
                "Attempted to invoke non-existing method");
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   186
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   187
        // trying to invoke the asbtract method "implementedMethod"
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   188
        testInvokeNeg(ifaceClass, ref, "implementedMethod", "()I", vm().mirrorOf(TARGET_CLASS_NAME),
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   189
                "Invocation of non-default methods is not supported");
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   190
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   191
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   192
        /* Static method calls */
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   193
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   194
        // invoke interface static method A
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   195
        testInvokePos(ifaceClass, null, "staticMethodA", "()I", vm().mirrorOf(RESULT_A));
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   196
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   197
        // try to invoke static method A on the instance
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   198
        testInvokePos(ifaceClass, ref, "staticMethodA", "()I", vm().mirrorOf(RESULT_A));
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   199
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   200
        // invoke interface static method B
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   201
        testInvokePos(ifaceClass, null, "staticMethodB", "()I", vm().mirrorOf(RESULT_A));
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   202
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   203
        // try to invoke static method B on the instance
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   204
        testInvokePos(ifaceClass, ref, "staticMethodB", "()I", vm().mirrorOf(RESULT_A));
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   205
    }
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   206
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   207
    private void testInterfaceB(ObjectReference ref) {
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   208
        // Test non-virtual calls on InterfaceB
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   209
        ReferenceType ifaceClass = (ReferenceType)vm().classesByName(INTERFACEB_NAME).get(0);
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   210
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   211
        /* Default method calls */
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   212
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   213
        // invoke the inherited "defaultMethodA"
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   214
        testInvokePos(ifaceClass, ref, "defaultMethodA", "()I", vm().mirrorOf(RESULT_A));
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   215
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   216
        // invoke the inherited "defaultMethodB"
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   217
        testInvokePos(ifaceClass, ref, "defaultMethodB", "()I", vm().mirrorOf(RESULT_A));
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   218
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   219
        // invoke the inherited and overridden "defaultMethodC"
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   220
        testInvokePos(ifaceClass, ref, "defaultMethodC", "()I", vm().mirrorOf(RESULT_B));
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   221
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   222
        // invoke InterfaceB only "defaultMethodD"
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   223
        testInvokePos(ifaceClass, ref, "defaultMethodD", "()I", vm().mirrorOf(RESULT_B));
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   224
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   225
        // "implementedMethod" is not present in InterfaceB
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   226
        testInvokeNeg(ifaceClass, ref, "implementedMethod", "()I", vm().mirrorOf(RESULT_TARGET),
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   227
                "Invocation of non-default methods is not supported");
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   228
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   229
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   230
        /* Static method calls*/
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   231
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   232
        // "staticMethodA" must not be inherited by InterfaceB
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   233
        testInvokeNeg(ifaceClass, null, "staticMethodA", "()I", vm().mirrorOf(RESULT_A),
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   234
                "Static interface methods are not inheritable");
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   235
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   236
        // however it is possible to call "staticMethodA" on the actual instance
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   237
        testInvokeNeg(ifaceClass, ref, "staticMethodA", "()I", vm().mirrorOf(RESULT_A),
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   238
                "Static interface methods are not inheritable");
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   239
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   240
        // "staticMethodB" is overridden in InterfaceB
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   241
        testInvokePos(ifaceClass, null, "staticMethodB", "()I", vm().mirrorOf(RESULT_B));
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   242
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   243
        // the instance invokes the overriden form of "staticMethodB" from InterfaceB
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   244
        testInvokePos(ifaceClass, ref, "staticMethodB", "()I", vm().mirrorOf(RESULT_B));
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   245
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   246
        // "staticMethodC" is present only in InterfaceB
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   247
        testInvokePos(ifaceClass, null, "staticMethodC", "()I", vm().mirrorOf(RESULT_B));
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   248
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   249
        // "staticMethodC" should be reachable from the instance too
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   250
        testInvokePos(ifaceClass, ref, "staticMethodC", "()I", vm().mirrorOf(RESULT_B));
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   251
    }
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   252
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   253
    private void testImplementationClass(ReferenceType targetClass, ObjectReference thisObject) {
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   254
        // Test invocations on the implementation object
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   255
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   256
        /* Default method calls */
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   257
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   258
        // "defaultMethodA" is accessible and not overridden
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   259
        testInvokePos(targetClass, thisObject, "defaultMethodA", "()I", vm().mirrorOf(RESULT_TARGET));
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   260
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   261
        // "defaultMethodB" is accessible and overridden in TargetClass
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   262
        testInvokePos(targetClass, thisObject, "defaultMethodB", "()I", vm().mirrorOf(RESULT_TARGET));
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   263
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   264
        // "defaultMethodC" is accessible and overridden in InterfaceB
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   265
        testInvokePos(targetClass, thisObject, "defaultMethodC", "()I", vm().mirrorOf(RESULT_TARGET));
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   266
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   267
        // "defaultMethodD" is accessible
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   268
        testInvokePos(targetClass, thisObject, "defaultMethodD", "()I", vm().mirrorOf(RESULT_TARGET));
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   269
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   270
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   271
        /* Non-default instance method calls */
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   272
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   273
        // "classMethod" declared in TargetClass is accessible
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   274
        testInvokePos(targetClass, thisObject, "classMethod", "()I", vm().mirrorOf(RESULT_TARGET));
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   275
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   276
        // the abstract "implementedMethod" has been implemented in TargetClass
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   277
        testInvokePos(targetClass, thisObject, "implementedMethod", "()I", vm().mirrorOf(RESULT_TARGET));
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   278
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   279
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   280
        /* Static method calls */
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   281
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   282
        // All the static methods declared by the interfaces are not reachable from the instance of the implementor class
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   283
        testInvokeNeg(targetClass, thisObject, "staticMethodA", "()I", vm().mirrorOf(RESULT_A),
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   284
                "Static interface methods are not inheritable");
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   285
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   286
        testInvokeNeg(targetClass, thisObject, "staticMethodB", "()I", vm().mirrorOf(RESULT_B),
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   287
                "Static interface methods are not inheritable");
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   288
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   289
        testInvokeNeg(targetClass, thisObject, "staticMethodC", "()I", vm().mirrorOf(RESULT_B),
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   290
                "Static interface methods are not inheritable");
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   291
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   292
        // All the static methods declared by the interfaces are not reachable through the implementor class
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   293
        testInvokeNeg(targetClass, null, "staticMethodA", "()I", vm().mirrorOf(RESULT_A),
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   294
                "Static interface methods are not inheritable");
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   295
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   296
        testInvokeNeg(targetClass, null, "staticMethodB", "()I", vm().mirrorOf(RESULT_B),
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   297
                "Static interface methods are not inheritable");
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   298
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   299
        testInvokeNeg(targetClass, null, "staticMethodC", "()I", vm().mirrorOf(RESULT_B),
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   300
                "Static interface methods are not inheritable");
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   301
    }
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   302
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   303
    private void testInvokePos(ReferenceType targetClass, ObjectReference ref, String methodName,
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   304
                               String methodSig, Value value) {
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   305
        logInvocation(ref, methodName, methodSig, targetClass);
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   306
        try {
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   307
            invoke(targetClass, ref, methodName, methodSig, value);
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   308
            System.err.println("--- PASSED");
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   309
        } catch (Exception e) {
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   310
            System.err.println("--- FAILED");
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   311
            failure("FAILED: Invocation failed with error message " + e.getLocalizedMessage());
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   312
        }
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   313
    }
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   314
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   315
    private void testInvokeNeg(ReferenceType targetClass, ObjectReference ref, String methodName,
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   316
                               String methodSig, Value value, String msg) {
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   317
        logInvocation(ref, methodName, methodSig, targetClass);
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   318
        try {
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   319
            invoke(targetClass, ref, methodName, methodSig, value);
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   320
            System.err.println("--- FAILED");
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   321
            failure("FAILED: " + msg);
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   322
        } catch (Exception e) {
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   323
            System.err.println("--- PASSED");
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   324
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   325
        }
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   326
    }
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   327
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   328
    private void invoke(ReferenceType targetClass, ObjectReference ref, String methodName,
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   329
                        String methodSig, Value value)
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   330
    throws Exception {
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   331
        Method method = getMethod(targetClass, methodName, methodSig);
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   332
        if (method == null) {
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   333
            throw new Exception("Can't find method: " + methodName  + " for class = " + targetClass);
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   334
        }
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   335
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   336
        println("Invoking " + (method.isAbstract() ? "abstract " : " ") + "method: " + method);
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   337
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   338
        Value returnValue = null;
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   339
        if (ref != null) {
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   340
            returnValue = invokeInstance(ref, method);
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   341
        } else {
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   342
            returnValue = invokeStatic(targetClass, method);
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   343
        }
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   344
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   345
        println("        return val = " + returnValue);
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   346
        // It has to be the same value as what we passed in!
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   347
        if (returnValue.equals(value)) {
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   348
            println("         " + method.name() + " return value matches: "
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   349
                    + value);
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   350
        } else {
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   351
            if (value != null) {
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   352
                throw new Exception(method.name() + " returned: " + returnValue +
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   353
                                    " expected: " + value );
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   354
            } else {
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   355
                println("         " + method.name() + " return value : " + returnValue);
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   356
            }
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   357
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   358
        }
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   359
    }
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   360
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   361
    private Value invokeInstance(ObjectReference ref, Method method) throws Exception {
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   362
        return ref.invokeMethod(mainThread, method, Collections.emptyList(), ObjectReference.INVOKE_NONVIRTUAL);
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   363
    }
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   364
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   365
    private Value invokeStatic(ReferenceType refType, Method method) throws Exception {
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   366
        if (refType instanceof ClassType) {
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   367
            return ((ClassType)refType).invokeMethod(mainThread, method, Collections.emptyList(), ObjectReference.INVOKE_NONVIRTUAL);
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   368
        } else {
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   369
            return ((InterfaceType)refType).invokeMethod(mainThread, method, Collections.emptyList(), ObjectReference.INVOKE_NONVIRTUAL);
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   370
        }
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   371
    }
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   372
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   373
    private Method getMethod(ReferenceType rt, String name, String signature) {
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   374
        if (rt == null) return null;
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   375
        Method m = findMethod(rt, name, signature);
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   376
        if (m == null) {
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   377
            if (rt instanceof ClassType) {
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   378
                for (Object ifc : ((ClassType)rt).interfaces()) {
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   379
                    m = getMethod((ReferenceType)ifc, name, signature);
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   380
                    if (m != null) {
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   381
                        break;
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   382
                    }
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   383
                }
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   384
                if (m == null) {
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   385
                    m = getMethod(((ClassType)rt).superclass(), name, signature);
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   386
                } else {
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   387
                    if (m.isStatic()) {
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   388
                        // interface static methods are not inherited
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   389
                        m = null;
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   390
                    }
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   391
                }
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   392
            } else if (rt instanceof InterfaceType) {
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   393
                for(Object ifc : ((InterfaceType)rt).superinterfaces()) {
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   394
                    m = getMethod((ReferenceType)ifc, name, signature);
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   395
                    if (m != null) {
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   396
                        if (m.isStatic()) {
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   397
                            // interface static methods are not inherited
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   398
                            m = null;
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   399
                        }
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   400
                        break;
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   401
                    }
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   402
                }
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   403
            }
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   404
        }
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   405
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   406
        return m;
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   407
    }
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   408
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   409
    private void logInvocation(ObjectReference ref, String methodName, String methodSig, ReferenceType targetClass) {
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   410
        if (ref != null) {
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   411
            System.err.println("Invoking: " + ref.referenceType().name() + "." +
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   412
                    methodName + methodSig + " with target of type " +
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   413
                    targetClass.name());
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   414
        } else {
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   415
            System.err.println("Invoking static : " + targetClass.name() + "." +
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   416
                    methodName + methodSig);
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   417
        }
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   418
    }
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   419
}
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   420
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   421
b85eeaae56c7 8031195: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
diff changeset
   422