3389N/A/*
3909N/A * Copyright (c) 2010, 2011, Oracle and/or its affiliates. All rights reserved.
3389N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
3389N/A *
3389N/A * This code is free software; you can redistribute it and/or modify it
3389N/A * under the terms of the GNU General Public License version 2 only, as
3389N/A * published by the Free Software Foundation.
3389N/A *
3389N/A * This code is distributed in the hope that it will be useful, but WITHOUT
3389N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
3389N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
3389N/A * version 2 for more details (a copy is included in the LICENSE file that
3389N/A * accompanied this code).
3389N/A *
3389N/A * You should have received a copy of the GNU General Public License version
3389N/A * 2 along with this work; if not, write to the Free Software Foundation,
3389N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
3389N/A *
3389N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
3389N/A * or visit www.oracle.com if you need additional information or have any
3389N/A * questions.
3389N/A */
3389N/A
3389N/A/**
3389N/A * @test
3389N/A * @bug 6426034
3389N/A * @summary Instance filter doesn't filter event if it occurs in native method
3389N/A *
3389N/A * @author Keith McGuigan
3389N/A *
3389N/A * @library scaffold
3389N/A * @run build JDIScaffold VMConnection
3389N/A * @compile -XDignore.symbol.file NativeInstanceFilterTarg.java
3389N/A * @run main/othervm NativeInstanceFilter
3389N/A */
3389N/A
3389N/A/*
3389N/A * This test tests instance filters for events generated from a native method
3389N/A */
3389N/A
3389N/Aimport java.util.*;
3389N/Aimport com.sun.jdi.*;
3389N/Aimport com.sun.jdi.event.*;
3389N/Aimport com.sun.jdi.request.*;
3389N/A
3389N/Apublic class NativeInstanceFilter extends JDIScaffold {
3389N/A
3389N/A static int unfilteredEvents = 0;
3389N/A
3389N/A public static void main(String args[]) throws Exception {
3389N/A new NativeInstanceFilter().startTests();
3389N/A }
3389N/A
3389N/A public NativeInstanceFilter() {
3389N/A super();
3389N/A }
3389N/A
3389N/A static EventRequestManager requestManager = null;
3389N/A static MethodExitRequest request = null;
3389N/A
3389N/A private void listen() {
3389N/A TargetAdapter adapter = new TargetAdapter() {
3389N/A EventSet set = null;
3389N/A ObjectReference instance = null;
3389N/A
3389N/A public boolean eventSetReceived(EventSet set) {
3389N/A this.set = set;
3389N/A return false;
3389N/A }
3389N/A
3389N/A public boolean methodExited(MethodExitEvent event) {
3389N/A String name = event.method().name();
3389N/A if (instance == null && name.equals("latch")) {
3389N/A // Grab the instance (return value) and set up as filter
3389N/A System.out.println("Setting up instance filter");
3389N/A instance = (ObjectReference)event.returnValue();
3389N/A requestManager.deleteEventRequest(request);
3389N/A request = requestManager.createMethodExitRequest();
3389N/A request.addInstanceFilter(instance);
3389N/A request.enable();
3389N/A } else if (instance != null && name.equals("intern")) {
3389N/A // If not for the filter, this will be called twice
3389N/A System.out.println("method exit event (String.intern())");
3389N/A ++unfilteredEvents;
3389N/A }
3389N/A set.resume();
3389N/A return false;
3389N/A }
3389N/A };
3389N/A addListener(adapter);
3389N/A }
3389N/A
3389N/A
3389N/A protected void runTests() throws Exception {
3389N/A String[] args = new String[2];
3389N/A args[0] = "-connect";
3389N/A args[1] = "com.sun.jdi.CommandLineLaunch:main=NativeInstanceFilterTarg";
3389N/A
3389N/A connect(args);
3389N/A waitForVMStart();
3389N/A
3389N/A // VM has started, but hasn't started running the test program yet.
3389N/A requestManager = vm().eventRequestManager();
3389N/A ReferenceType referenceType =
3389N/A resumeToPrepareOf("NativeInstanceFilterTarg").referenceType();
3389N/A
3389N/A request = requestManager.createMethodExitRequest();
3389N/A request.enable();
3389N/A
3389N/A listen();
3389N/A
3389N/A vm().resume();
3389N/A
3389N/A waitForVMDeath();
3389N/A
3389N/A if (unfilteredEvents != 1) {
3389N/A throw new Exception(
3389N/A "Failed: Event from native frame not filtered out.");
3389N/A }
3389N/A System.out.println("Passed: Event filtered out.");
3389N/A }
3389N/A}