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 4.2KB

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