jdk/test/java/lang/instrument/RedefineMethodInBacktraceApp.java
changeset 30355 e37c7eba132f
parent 30327 14a05668b003
equal deleted inserted replaced
30354:ca83b4cae363 30355:e37c7eba132f
     1 /*
     1 /*
     2  * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 2013, 2015, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.
     7  * published by the Free Software Foundation.
    29 import java.lang.management.ManagementFactory;
    29 import java.lang.management.ManagementFactory;
    30 import java.lang.management.ThreadInfo;
    30 import java.lang.management.ThreadInfo;
    31 import java.lang.reflect.InvocationTargetException;
    31 import java.lang.reflect.InvocationTargetException;
    32 import java.lang.reflect.Method;
    32 import java.lang.reflect.Method;
    33 import java.util.concurrent.CountDownLatch;
    33 import java.util.concurrent.CountDownLatch;
    34 import sun.management.ManagementFactoryHelper;
    34 import javax.management.JMX;
       
    35 import javax.management.ObjectName;
    35 
    36 
    36 /**
    37 /**
    37  * When an exception is thrown, the JVM collects just enough information
    38  * When an exception is thrown, the JVM collects just enough information
    38  * about the stack trace to be able to create a full fledged stack trace
    39  * about the stack trace to be able to create a full fledged stack trace
    39  * (StackTraceElement[]). The backtrace contains this information and the
    40  * (StackTraceElement[]). The backtrace contains this information and the
   101         }
   102         }
   102 
   103 
   103         String[] threadPrintArgs = {};
   104         String[] threadPrintArgs = {};
   104         Object[] dcmdArgs = {threadPrintArgs};
   105         Object[] dcmdArgs = {threadPrintArgs};
   105         String[] signature = {String[].class.getName()};
   106         String[] signature = {String[].class.getName()};
   106         DiagnosticCommandMBean dcmd = ManagementFactoryHelper.getDiagnosticCommandMBean();
   107         System.out.println(ManagementFactory.getPlatformMBeanServer().invoke(
   107         System.out.println(dcmd.invoke("threadPrint", dcmdArgs, signature));
   108                 ObjectName.getInstance("com.sun.management:type=DiagnosticCommand"),
       
   109                 "threadPrint",
       
   110                 dcmdArgs,
       
   111                 signature));
   108 
   112 
   109         // release the thread
   113         // release the thread
   110         stop.countDown();
   114         stop.countDown();
   111     }
   115     }
   112 
   116