jdk/test/com/sun/jdi/VisibleMethods.java
author alexsch
Thu, 31 Jul 2014 14:28:10 +0400
changeset 26019 10a56d28f48d
parent 24973 8c4bc3fa4c4e
child 30376 2ccf2cf7ea48
permissions -rw-r--r--
8051838: [Findbugs]sun.awt.image.MultiResolutionCachedImage expose internal representation Reviewed-by: serb, pchelko
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
22049
15b9d7db4ad7 8028430: JDI: ReferenceType.visibleMethods() return wrong visible methods
sla
parents:
diff changeset
     1
/*
15b9d7db4ad7 8028430: JDI: ReferenceType.visibleMethods() return wrong visible methods
sla
parents:
diff changeset
     2
 * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
15b9d7db4ad7 8028430: JDI: ReferenceType.visibleMethods() return wrong visible methods
sla
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
15b9d7db4ad7 8028430: JDI: ReferenceType.visibleMethods() return wrong visible methods
sla
parents:
diff changeset
     4
 *
15b9d7db4ad7 8028430: JDI: ReferenceType.visibleMethods() return wrong visible methods
sla
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
15b9d7db4ad7 8028430: JDI: ReferenceType.visibleMethods() return wrong visible methods
sla
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
15b9d7db4ad7 8028430: JDI: ReferenceType.visibleMethods() return wrong visible methods
sla
parents:
diff changeset
     7
 * published by the Free Software Foundation.
15b9d7db4ad7 8028430: JDI: ReferenceType.visibleMethods() return wrong visible methods
sla
parents:
diff changeset
     8
 *
15b9d7db4ad7 8028430: JDI: ReferenceType.visibleMethods() return wrong visible methods
sla
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
15b9d7db4ad7 8028430: JDI: ReferenceType.visibleMethods() return wrong visible methods
sla
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
15b9d7db4ad7 8028430: JDI: ReferenceType.visibleMethods() return wrong visible methods
sla
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
15b9d7db4ad7 8028430: JDI: ReferenceType.visibleMethods() return wrong visible methods
sla
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
15b9d7db4ad7 8028430: JDI: ReferenceType.visibleMethods() return wrong visible methods
sla
parents:
diff changeset
    13
 * accompanied this code).
15b9d7db4ad7 8028430: JDI: ReferenceType.visibleMethods() return wrong visible methods
sla
parents:
diff changeset
    14
 *
15b9d7db4ad7 8028430: JDI: ReferenceType.visibleMethods() return wrong visible methods
sla
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
15b9d7db4ad7 8028430: JDI: ReferenceType.visibleMethods() return wrong visible methods
sla
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
15b9d7db4ad7 8028430: JDI: ReferenceType.visibleMethods() return wrong visible methods
sla
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
15b9d7db4ad7 8028430: JDI: ReferenceType.visibleMethods() return wrong visible methods
sla
parents:
diff changeset
    18
 *
15b9d7db4ad7 8028430: JDI: ReferenceType.visibleMethods() return wrong visible methods
sla
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
15b9d7db4ad7 8028430: JDI: ReferenceType.visibleMethods() return wrong visible methods
sla
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
15b9d7db4ad7 8028430: JDI: ReferenceType.visibleMethods() return wrong visible methods
sla
parents:
diff changeset
    21
 * questions.
15b9d7db4ad7 8028430: JDI: ReferenceType.visibleMethods() return wrong visible methods
sla
parents:
diff changeset
    22
 */
15b9d7db4ad7 8028430: JDI: ReferenceType.visibleMethods() return wrong visible methods
sla
parents:
diff changeset
    23
15b9d7db4ad7 8028430: JDI: ReferenceType.visibleMethods() return wrong visible methods
sla
parents:
diff changeset
    24
/**
15b9d7db4ad7 8028430: JDI: ReferenceType.visibleMethods() return wrong visible methods
sla
parents:
diff changeset
    25
 *  @test
15b9d7db4ad7 8028430: JDI: ReferenceType.visibleMethods() return wrong visible methods
sla
parents:
diff changeset
    26
 *  @summary Test ReferenceType.visibleMethods
15b9d7db4ad7 8028430: JDI: ReferenceType.visibleMethods() return wrong visible methods
sla
parents:
diff changeset
    27
 *  @bug 8028430
15b9d7db4ad7 8028430: JDI: ReferenceType.visibleMethods() return wrong visible methods
sla
parents:
diff changeset
    28
 *
15b9d7db4ad7 8028430: JDI: ReferenceType.visibleMethods() return wrong visible methods
sla
parents:
diff changeset
    29
 *  @author Staffan Larsen
15b9d7db4ad7 8028430: JDI: ReferenceType.visibleMethods() return wrong visible methods
sla
parents:
diff changeset
    30
 *
15b9d7db4ad7 8028430: JDI: ReferenceType.visibleMethods() return wrong visible methods
sla
parents:
diff changeset
    31
 *  @run build TestScaffold VMConnection TargetListener TargetAdapter
15b9d7db4ad7 8028430: JDI: ReferenceType.visibleMethods() return wrong visible methods
sla
parents:
diff changeset
    32
 *  @run compile -g VisibleMethods.java
24973
8c4bc3fa4c4e 6622468: TEST_BUG: Time to retire the @debuggeeVMOptions mechanism used in the com.sun.jdi infrastructure
sla
parents: 22049
diff changeset
    33
 *  @run driver VisibleMethods
22049
15b9d7db4ad7 8028430: JDI: ReferenceType.visibleMethods() return wrong visible methods
sla
parents:
diff changeset
    34
 */
15b9d7db4ad7 8028430: JDI: ReferenceType.visibleMethods() return wrong visible methods
sla
parents:
diff changeset
    35
import com.sun.jdi.Method;
15b9d7db4ad7 8028430: JDI: ReferenceType.visibleMethods() return wrong visible methods
sla
parents:
diff changeset
    36
import com.sun.jdi.ReferenceType;
15b9d7db4ad7 8028430: JDI: ReferenceType.visibleMethods() return wrong visible methods
sla
parents:
diff changeset
    37
import com.sun.jdi.StackFrame;
15b9d7db4ad7 8028430: JDI: ReferenceType.visibleMethods() return wrong visible methods
sla
parents:
diff changeset
    38
import com.sun.jdi.StringReference;
15b9d7db4ad7 8028430: JDI: ReferenceType.visibleMethods() return wrong visible methods
sla
parents:
diff changeset
    39
import com.sun.jdi.ThreadReference;
15b9d7db4ad7 8028430: JDI: ReferenceType.visibleMethods() return wrong visible methods
sla
parents:
diff changeset
    40
import com.sun.jdi.event.BreakpointEvent;
15b9d7db4ad7 8028430: JDI: ReferenceType.visibleMethods() return wrong visible methods
sla
parents:
diff changeset
    41
15b9d7db4ad7 8028430: JDI: ReferenceType.visibleMethods() return wrong visible methods
sla
parents:
diff changeset
    42
import java.util.Arrays;
15b9d7db4ad7 8028430: JDI: ReferenceType.visibleMethods() return wrong visible methods
sla
parents:
diff changeset
    43
import java.util.List;
15b9d7db4ad7 8028430: JDI: ReferenceType.visibleMethods() return wrong visible methods
sla
parents:
diff changeset
    44
import java.util.stream.Collectors;
15b9d7db4ad7 8028430: JDI: ReferenceType.visibleMethods() return wrong visible methods
sla
parents:
diff changeset
    45
15b9d7db4ad7 8028430: JDI: ReferenceType.visibleMethods() return wrong visible methods
sla
parents:
diff changeset
    46
/********** target program **********/
15b9d7db4ad7 8028430: JDI: ReferenceType.visibleMethods() return wrong visible methods
sla
parents:
diff changeset
    47
15b9d7db4ad7 8028430: JDI: ReferenceType.visibleMethods() return wrong visible methods
sla
parents:
diff changeset
    48
interface Super {
15b9d7db4ad7 8028430: JDI: ReferenceType.visibleMethods() return wrong visible methods
sla
parents:
diff changeset
    49
    public void m(Object o); // This method should not be visible in AC
15b9d7db4ad7 8028430: JDI: ReferenceType.visibleMethods() return wrong visible methods
sla
parents:
diff changeset
    50
    public void m(String s); // This method should not be visible in AC
15b9d7db4ad7 8028430: JDI: ReferenceType.visibleMethods() return wrong visible methods
sla
parents:
diff changeset
    51
}
15b9d7db4ad7 8028430: JDI: ReferenceType.visibleMethods() return wrong visible methods
sla
parents:
diff changeset
    52
15b9d7db4ad7 8028430: JDI: ReferenceType.visibleMethods() return wrong visible methods
sla
parents:
diff changeset
    53
interface One extends Super {
15b9d7db4ad7 8028430: JDI: ReferenceType.visibleMethods() return wrong visible methods
sla
parents:
diff changeset
    54
    public void m(Object o);
15b9d7db4ad7 8028430: JDI: ReferenceType.visibleMethods() return wrong visible methods
sla
parents:
diff changeset
    55
    public void m1(); // Either this method or Two.m1 should be visible in AC
15b9d7db4ad7 8028430: JDI: ReferenceType.visibleMethods() return wrong visible methods
sla
parents:
diff changeset
    56
}
15b9d7db4ad7 8028430: JDI: ReferenceType.visibleMethods() return wrong visible methods
sla
parents:
diff changeset
    57
15b9d7db4ad7 8028430: JDI: ReferenceType.visibleMethods() return wrong visible methods
sla
parents:
diff changeset
    58
interface Two extends Super {
15b9d7db4ad7 8028430: JDI: ReferenceType.visibleMethods() return wrong visible methods
sla
parents:
diff changeset
    59
    public void m(String s);
15b9d7db4ad7 8028430: JDI: ReferenceType.visibleMethods() return wrong visible methods
sla
parents:
diff changeset
    60
    public void m1(); // Either this method or One.m1 should be visible in AC
15b9d7db4ad7 8028430: JDI: ReferenceType.visibleMethods() return wrong visible methods
sla
parents:
diff changeset
    61
}
15b9d7db4ad7 8028430: JDI: ReferenceType.visibleMethods() return wrong visible methods
sla
parents:
diff changeset
    62
15b9d7db4ad7 8028430: JDI: ReferenceType.visibleMethods() return wrong visible methods
sla
parents:
diff changeset
    63
abstract class AC implements One, Two {
15b9d7db4ad7 8028430: JDI: ReferenceType.visibleMethods() return wrong visible methods
sla
parents:
diff changeset
    64
}
15b9d7db4ad7 8028430: JDI: ReferenceType.visibleMethods() return wrong visible methods
sla
parents:
diff changeset
    65
15b9d7db4ad7 8028430: JDI: ReferenceType.visibleMethods() return wrong visible methods
sla
parents:
diff changeset
    66
class CC extends AC {
15b9d7db4ad7 8028430: JDI: ReferenceType.visibleMethods() return wrong visible methods
sla
parents:
diff changeset
    67
    public void m(Object o) {
15b9d7db4ad7 8028430: JDI: ReferenceType.visibleMethods() return wrong visible methods
sla
parents:
diff changeset
    68
    }
15b9d7db4ad7 8028430: JDI: ReferenceType.visibleMethods() return wrong visible methods
sla
parents:
diff changeset
    69
    public void m(String s) {
15b9d7db4ad7 8028430: JDI: ReferenceType.visibleMethods() return wrong visible methods
sla
parents:
diff changeset
    70
    }
15b9d7db4ad7 8028430: JDI: ReferenceType.visibleMethods() return wrong visible methods
sla
parents:
diff changeset
    71
    public void m1() {
15b9d7db4ad7 8028430: JDI: ReferenceType.visibleMethods() return wrong visible methods
sla
parents:
diff changeset
    72
    }
15b9d7db4ad7 8028430: JDI: ReferenceType.visibleMethods() return wrong visible methods
sla
parents:
diff changeset
    73
    public static void main(String[] args) {
15b9d7db4ad7 8028430: JDI: ReferenceType.visibleMethods() return wrong visible methods
sla
parents:
diff changeset
    74
        System.out.println("Goodbye from VisibleMethods!");
15b9d7db4ad7 8028430: JDI: ReferenceType.visibleMethods() return wrong visible methods
sla
parents:
diff changeset
    75
    }
15b9d7db4ad7 8028430: JDI: ReferenceType.visibleMethods() return wrong visible methods
sla
parents:
diff changeset
    76
}
15b9d7db4ad7 8028430: JDI: ReferenceType.visibleMethods() return wrong visible methods
sla
parents:
diff changeset
    77
15b9d7db4ad7 8028430: JDI: ReferenceType.visibleMethods() return wrong visible methods
sla
parents:
diff changeset
    78
/********** test program **********/
15b9d7db4ad7 8028430: JDI: ReferenceType.visibleMethods() return wrong visible methods
sla
parents:
diff changeset
    79
15b9d7db4ad7 8028430: JDI: ReferenceType.visibleMethods() return wrong visible methods
sla
parents:
diff changeset
    80
public class VisibleMethods extends TestScaffold {
15b9d7db4ad7 8028430: JDI: ReferenceType.visibleMethods() return wrong visible methods
sla
parents:
diff changeset
    81
    ReferenceType targetClass;
15b9d7db4ad7 8028430: JDI: ReferenceType.visibleMethods() return wrong visible methods
sla
parents:
diff changeset
    82
    ThreadReference mainThread;
15b9d7db4ad7 8028430: JDI: ReferenceType.visibleMethods() return wrong visible methods
sla
parents:
diff changeset
    83
15b9d7db4ad7 8028430: JDI: ReferenceType.visibleMethods() return wrong visible methods
sla
parents:
diff changeset
    84
    VisibleMethods(String args[]) {
15b9d7db4ad7 8028430: JDI: ReferenceType.visibleMethods() return wrong visible methods
sla
parents:
diff changeset
    85
        super(args);
15b9d7db4ad7 8028430: JDI: ReferenceType.visibleMethods() return wrong visible methods
sla
parents:
diff changeset
    86
    }
15b9d7db4ad7 8028430: JDI: ReferenceType.visibleMethods() return wrong visible methods
sla
parents:
diff changeset
    87
15b9d7db4ad7 8028430: JDI: ReferenceType.visibleMethods() return wrong visible methods
sla
parents:
diff changeset
    88
    public static void main(String[] args) throws Exception {
15b9d7db4ad7 8028430: JDI: ReferenceType.visibleMethods() return wrong visible methods
sla
parents:
diff changeset
    89
        new VisibleMethods(args).startTests();
15b9d7db4ad7 8028430: JDI: ReferenceType.visibleMethods() return wrong visible methods
sla
parents:
diff changeset
    90
    }
15b9d7db4ad7 8028430: JDI: ReferenceType.visibleMethods() return wrong visible methods
sla
parents:
diff changeset
    91
15b9d7db4ad7 8028430: JDI: ReferenceType.visibleMethods() return wrong visible methods
sla
parents:
diff changeset
    92
    /********** test core **********/
15b9d7db4ad7 8028430: JDI: ReferenceType.visibleMethods() return wrong visible methods
sla
parents:
diff changeset
    93
15b9d7db4ad7 8028430: JDI: ReferenceType.visibleMethods() return wrong visible methods
sla
parents:
diff changeset
    94
    protected void runTests()
15b9d7db4ad7 8028430: JDI: ReferenceType.visibleMethods() return wrong visible methods
sla
parents:
diff changeset
    95
        throws Exception
15b9d7db4ad7 8028430: JDI: ReferenceType.visibleMethods() return wrong visible methods
sla
parents:
diff changeset
    96
    {
15b9d7db4ad7 8028430: JDI: ReferenceType.visibleMethods() return wrong visible methods
sla
parents:
diff changeset
    97
        /*
15b9d7db4ad7 8028430: JDI: ReferenceType.visibleMethods() return wrong visible methods
sla
parents:
diff changeset
    98
         * Run to String.<init>
15b9d7db4ad7 8028430: JDI: ReferenceType.visibleMethods() return wrong visible methods
sla
parents:
diff changeset
    99
         */
15b9d7db4ad7 8028430: JDI: ReferenceType.visibleMethods() return wrong visible methods
sla
parents:
diff changeset
   100
        startToMain("CC");
15b9d7db4ad7 8028430: JDI: ReferenceType.visibleMethods() return wrong visible methods
sla
parents:
diff changeset
   101
15b9d7db4ad7 8028430: JDI: ReferenceType.visibleMethods() return wrong visible methods
sla
parents:
diff changeset
   102
        ReferenceType ac = findReferenceType("AC");
15b9d7db4ad7 8028430: JDI: ReferenceType.visibleMethods() return wrong visible methods
sla
parents:
diff changeset
   103
        List<String> visible = ac.visibleMethods().
15b9d7db4ad7 8028430: JDI: ReferenceType.visibleMethods() return wrong visible methods
sla
parents:
diff changeset
   104
                stream().
15b9d7db4ad7 8028430: JDI: ReferenceType.visibleMethods() return wrong visible methods
sla
parents:
diff changeset
   105
                map(Method::toString).
15b9d7db4ad7 8028430: JDI: ReferenceType.visibleMethods() return wrong visible methods
sla
parents:
diff changeset
   106
                collect(Collectors.toList());
15b9d7db4ad7 8028430: JDI: ReferenceType.visibleMethods() return wrong visible methods
sla
parents:
diff changeset
   107
15b9d7db4ad7 8028430: JDI: ReferenceType.visibleMethods() return wrong visible methods
sla
parents:
diff changeset
   108
        System.out.println("visibleMethods(): " + visible);
15b9d7db4ad7 8028430: JDI: ReferenceType.visibleMethods() return wrong visible methods
sla
parents:
diff changeset
   109
15b9d7db4ad7 8028430: JDI: ReferenceType.visibleMethods() return wrong visible methods
sla
parents:
diff changeset
   110
        verifyContains(visible, 1, "Two.m(java.lang.String)");
15b9d7db4ad7 8028430: JDI: ReferenceType.visibleMethods() return wrong visible methods
sla
parents:
diff changeset
   111
        verifyContains(visible, 1, "One.m(java.lang.Object)");
15b9d7db4ad7 8028430: JDI: ReferenceType.visibleMethods() return wrong visible methods
sla
parents:
diff changeset
   112
        verifyContains(visible, 0, "Super.m(java.lang.Object)");
15b9d7db4ad7 8028430: JDI: ReferenceType.visibleMethods() return wrong visible methods
sla
parents:
diff changeset
   113
        verifyContains(visible, 0, "Super.m(java.lang.String)");
15b9d7db4ad7 8028430: JDI: ReferenceType.visibleMethods() return wrong visible methods
sla
parents:
diff changeset
   114
        verifyContains(visible, 1, "Two.m1()", "One.m1()");
15b9d7db4ad7 8028430: JDI: ReferenceType.visibleMethods() return wrong visible methods
sla
parents:
diff changeset
   115
15b9d7db4ad7 8028430: JDI: ReferenceType.visibleMethods() return wrong visible methods
sla
parents:
diff changeset
   116
        /*
15b9d7db4ad7 8028430: JDI: ReferenceType.visibleMethods() return wrong visible methods
sla
parents:
diff changeset
   117
         * resume the target listening for events
15b9d7db4ad7 8028430: JDI: ReferenceType.visibleMethods() return wrong visible methods
sla
parents:
diff changeset
   118
         */
15b9d7db4ad7 8028430: JDI: ReferenceType.visibleMethods() return wrong visible methods
sla
parents:
diff changeset
   119
        listenUntilVMDisconnect();
15b9d7db4ad7 8028430: JDI: ReferenceType.visibleMethods() return wrong visible methods
sla
parents:
diff changeset
   120
    }
15b9d7db4ad7 8028430: JDI: ReferenceType.visibleMethods() return wrong visible methods
sla
parents:
diff changeset
   121
15b9d7db4ad7 8028430: JDI: ReferenceType.visibleMethods() return wrong visible methods
sla
parents:
diff changeset
   122
    private void verifyContains(List<String> methods, int matches,
15b9d7db4ad7 8028430: JDI: ReferenceType.visibleMethods() return wrong visible methods
sla
parents:
diff changeset
   123
            String... sigs) throws Exception {
15b9d7db4ad7 8028430: JDI: ReferenceType.visibleMethods() return wrong visible methods
sla
parents:
diff changeset
   124
        if (countMatches(methods, sigs) != matches) {
15b9d7db4ad7 8028430: JDI: ReferenceType.visibleMethods() return wrong visible methods
sla
parents:
diff changeset
   125
            throw new Exception("visibleMethods() should have contained "
15b9d7db4ad7 8028430: JDI: ReferenceType.visibleMethods() return wrong visible methods
sla
parents:
diff changeset
   126
                    + matches + " entry/entries from " + Arrays.toString(sigs));
15b9d7db4ad7 8028430: JDI: ReferenceType.visibleMethods() return wrong visible methods
sla
parents:
diff changeset
   127
        }
15b9d7db4ad7 8028430: JDI: ReferenceType.visibleMethods() return wrong visible methods
sla
parents:
diff changeset
   128
    }
15b9d7db4ad7 8028430: JDI: ReferenceType.visibleMethods() return wrong visible methods
sla
parents:
diff changeset
   129
15b9d7db4ad7 8028430: JDI: ReferenceType.visibleMethods() return wrong visible methods
sla
parents:
diff changeset
   130
    private int countMatches(List<String> list1, String[] list2) {
15b9d7db4ad7 8028430: JDI: ReferenceType.visibleMethods() return wrong visible methods
sla
parents:
diff changeset
   131
        int count = 0;
15b9d7db4ad7 8028430: JDI: ReferenceType.visibleMethods() return wrong visible methods
sla
parents:
diff changeset
   132
        for (String s1 : list1) {
15b9d7db4ad7 8028430: JDI: ReferenceType.visibleMethods() return wrong visible methods
sla
parents:
diff changeset
   133
            for (String s2 : list2) {
15b9d7db4ad7 8028430: JDI: ReferenceType.visibleMethods() return wrong visible methods
sla
parents:
diff changeset
   134
                if (s1.equals(s2)) {
15b9d7db4ad7 8028430: JDI: ReferenceType.visibleMethods() return wrong visible methods
sla
parents:
diff changeset
   135
                    count++;
15b9d7db4ad7 8028430: JDI: ReferenceType.visibleMethods() return wrong visible methods
sla
parents:
diff changeset
   136
                }
15b9d7db4ad7 8028430: JDI: ReferenceType.visibleMethods() return wrong visible methods
sla
parents:
diff changeset
   137
            }
15b9d7db4ad7 8028430: JDI: ReferenceType.visibleMethods() return wrong visible methods
sla
parents:
diff changeset
   138
        }
15b9d7db4ad7 8028430: JDI: ReferenceType.visibleMethods() return wrong visible methods
sla
parents:
diff changeset
   139
        return count;
15b9d7db4ad7 8028430: JDI: ReferenceType.visibleMethods() return wrong visible methods
sla
parents:
diff changeset
   140
    }
15b9d7db4ad7 8028430: JDI: ReferenceType.visibleMethods() return wrong visible methods
sla
parents:
diff changeset
   141
}