You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

RedefineObjectClassTest.java 3.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. /*
  2. * Copyright (c) 2010, 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. package com.github.dcevm.test.structural;
  25. import com.github.dcevm.ClassRedefinitionPolicy;
  26. import com.github.dcevm.test.category.Full;
  27. import org.junit.Before;
  28. import org.junit.Ignore;
  29. import org.junit.Test;
  30. import org.junit.experimental.categories.Category;
  31. import static com.github.dcevm.test.util.HotSwapTestHelper.__toVersion__;
  32. import static com.github.dcevm.test.util.HotSwapTestHelper.__version__;
  33. import static org.junit.Assert.assertEquals;
  34. /**
  35. * Smallest test case for redefining java/lang/Object, without changing the number of virtual methods.
  36. *
  37. * @author Thomas Wuerthinger
  38. */
  39. @Category(Full.class)
  40. @Ignore
  41. public class RedefineObjectClassTest {
  42. // Version 0
  43. public static class Helper {
  44. public static String access(Object o) {
  45. return "";
  46. }
  47. }
  48. // Version 1
  49. public static class Helper___1 {
  50. public static String access(Object o) {
  51. return ((A___1) o).myTestFunction___();
  52. }
  53. }
  54. @ClassRedefinitionPolicy(alias = java.lang.Object.class)
  55. public static class A___1 {
  56. public final native Class<? extends Object> getClass___();
  57. public native int hashCode();
  58. public boolean equals(Object obj) {
  59. return (this == obj);
  60. }
  61. public static int x;
  62. public static int x1;
  63. public static int x2;
  64. public static int x3;
  65. public static int x4;
  66. public static int x5;
  67. protected native Object clone() throws CloneNotSupportedException;
  68. public String toString() {
  69. System.out.println("x=" + (x++));
  70. return getClass().getName() + "@" + Integer.toHexString(hashCode());// myTestFunction___();
  71. }
  72. public final String myTestFunction___() {
  73. return "test";
  74. }
  75. public final native void notify___();
  76. public final native void notifyAll___();
  77. public final native void wait___(long timeout) throws InterruptedException;
  78. public final void wait___(long timeout, int nanos) throws InterruptedException {
  79. if (timeout < 0) {
  80. throw new IllegalArgumentException("timeout value is negative");
  81. }
  82. if (nanos < 0 || nanos > 999999) {
  83. throw new IllegalArgumentException(
  84. "nanosecond timeout value out of range");
  85. }
  86. if (nanos >= 500000 || (nanos != 0 && timeout == 0)) {
  87. timeout++;
  88. }
  89. wait(timeout);
  90. }
  91. public final void wait___() throws InterruptedException {
  92. wait(0);
  93. }
  94. protected void finalize() throws Throwable {
  95. }
  96. }
  97. @Before
  98. public void setUp() throws Exception {
  99. __toVersion__(0);
  100. }
  101. @Test
  102. public void testRedefineObject() {
  103. assert __version__() == 0;
  104. Object o = new Object();
  105. __toVersion__(1);
  106. System.out.println(this.toString());
  107. System.out.println(o.toString());
  108. System.out.println(this.toString());
  109. //assertEquals("test", o.toString());
  110. assertEquals("test", Helper.access(o));
  111. __toVersion__(0);
  112. __toVersion__(1);
  113. __toVersion__(0);
  114. }
  115. }