/jdk/test/com/sun/jdi/VMDeathLastTest.java

https://github.com/Morriar/ProxyJDK · Java · 142 lines · 71 code · 18 blank · 53 comment · 8 complexity · 9e96beb089a1e1aec9927602ae2b2d24 MD5 · raw file

  1. /*
  2. * Copyright (c) 2001, 2003, Oracle and/or its affiliates. All rights reserved.
  3. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  4. *
  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
  7. * published by the Free Software Foundation.
  8. *
  9. * This code is distributed in the hope that it will be useful, but WITHOUT
  10. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  12. * version 2 for more details (a copy is included in the LICENSE file that
  13. * accompanied this code).
  14. *
  15. * You should have received a copy of the GNU General Public License version
  16. * 2 along with this work; if not, write to the Free Software Foundation,
  17. * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18. *
  19. * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20. * or visit www.oracle.com if you need additional information or have any
  21. * questions.
  22. */
  23. /**
  24. * @test
  25. * @bug 4420844 4449394
  26. * @summary Checks that no events are sent after VMDeath, and test vm.canBeModified
  27. *
  28. * @author Robert Field
  29. *
  30. * @run build TestScaffold VMConnection TargetListener TargetAdapter
  31. * @run compile -g HelloWorld.java
  32. * @run build VMDeathLastTest
  33. * @run main VMDeathLastTest
  34. */
  35. import com.sun.jdi.*;
  36. import com.sun.jdi.event.*;
  37. import com.sun.jdi.request.*;
  38. import java.util.*;
  39. /********** test program **********/
  40. public class VMDeathLastTest extends TestScaffold {
  41. Object syncer = new Object();
  42. boolean vmDead = false;
  43. boolean disconnected = false;
  44. VMDeathLastTest (String args[]) {
  45. super(args);
  46. }
  47. public static void main(String[] args) throws Exception {
  48. new VMDeathLastTest(args).startTests();
  49. }
  50. /********** event handlers **********/
  51. public void methodEntered(MethodEntryEvent event) {
  52. if (vmDead) {
  53. failure("Failure: Got MethodEntryEvent after VM Dead");
  54. }
  55. }
  56. public void classPrepared(ClassPrepareEvent event) {
  57. if (vmDead) {
  58. failure("Failure: Got ClassPrepareEvent after VM Dead");
  59. }
  60. }
  61. public void threadDied(ThreadDeathEvent event) {
  62. if (vmDead) {
  63. failure("Failure: Got ThreadDeathEvent after VM Dead");
  64. }
  65. }
  66. public void vmDied(VMDeathEvent event) {
  67. println("Got VMDeathEvent");
  68. vmDead = true;
  69. }
  70. public void vmDisconnected(VMDisconnectEvent event) {
  71. println("Got VMDisconnectEvent");
  72. if (!vmDead) {
  73. failure("Test failure: didn't get VMDeath");
  74. }
  75. disconnected = true;
  76. synchronized (syncer) {
  77. syncer.notifyAll();
  78. }
  79. }
  80. /**
  81. * Turn off default VMDeath handling.
  82. */
  83. protected void createDefaultVMDeathRequest() {
  84. }
  85. /********** test core **********/
  86. protected void runTests() throws Exception {
  87. /*
  88. * Get to the top of main()
  89. * to determine targetClass and mainThread
  90. */
  91. startToMain("HelloWorld");
  92. if (!vm().canBeModified()) {
  93. failure("VM says it is read-only");
  94. }
  95. EventRequestManager erm = vm().eventRequestManager();
  96. /*
  97. * Set event requests
  98. */
  99. erm.createMethodEntryRequest().enable();
  100. erm.createClassPrepareRequest().enable();
  101. erm.createThreadDeathRequest().enable();
  102. /*
  103. * resume the target listening for events
  104. */
  105. addListener(this);
  106. synchronized (syncer) {
  107. vm().resume();
  108. while (!disconnected) {
  109. try {
  110. syncer.wait();
  111. } catch (InterruptedException e) {
  112. }
  113. }
  114. }
  115. /*
  116. * deal with results of test
  117. */
  118. if (!testFailed) {
  119. println("VMDeathLastTest: passed");
  120. } else {
  121. throw new Exception("VMDeathLastTest: failed");
  122. }
  123. }
  124. }