2014-05-28 14:36:32 +00:00
|
|
|
/*
|
2019-12-16 18:04:36 +00:00
|
|
|
* Copyright (c) 2014, 2019, Oracle and/or its affiliates. All rights reserved.
|
2014-05-28 14:36:32 +00:00
|
|
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
|
|
*
|
|
|
|
* This code is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU General Public License version 2 only, as
|
|
|
|
* published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This code is distributed in the hope that it will be useful, but WITHOUT
|
|
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
|
|
* version 2 for more details (a copy is included in the LICENSE file that
|
|
|
|
* accompanied this code).
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License version
|
|
|
|
* 2 along with this work; if not, write to the Free Software Foundation,
|
|
|
|
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*
|
|
|
|
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
|
|
|
* or visit www.oracle.com if you need additional information or have any
|
|
|
|
* questions.
|
|
|
|
*/
|
|
|
|
|
2014-06-02 17:08:18 +00:00
|
|
|
/*
|
|
|
|
* @test
|
2016-08-19 14:06:30 +00:00
|
|
|
* @library /test/lib
|
2014-06-02 17:08:18 +00:00
|
|
|
* @summary Proof of concept test for RedefineClassHelper
|
2016-05-01 09:47:00 +00:00
|
|
|
* @modules java.base/jdk.internal.misc
|
2015-03-26 15:36:56 +00:00
|
|
|
* @modules java.compiler
|
|
|
|
* java.instrument
|
2014-06-02 17:08:18 +00:00
|
|
|
* @run main RedefineClassHelper
|
|
|
|
* @run main/othervm -javaagent:redefineagent.jar RedefineClassTest
|
|
|
|
*/
|
|
|
|
|
2015-05-04 14:30:07 +00:00
|
|
|
import static jdk.test.lib.Asserts.*;
|
2014-05-28 14:36:32 +00:00
|
|
|
|
2014-06-02 17:08:18 +00:00
|
|
|
/*
|
|
|
|
* Proof of concept test for the test utility class RedefineClassHelper
|
|
|
|
*/
|
2018-06-23 05:32:41 +00:00
|
|
|
|
|
|
|
// package access top-level class to avoid problem with RedefineClassHelper
|
|
|
|
// and nested types.
|
|
|
|
class RedefineClassTest_A {
|
|
|
|
public int Method() {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-02 17:08:18 +00:00
|
|
|
public class RedefineClassTest {
|
|
|
|
|
2018-06-23 05:32:41 +00:00
|
|
|
public static String newClass = "class RedefineClassTest_A { public int Method() { return 2; } }";
|
2014-06-02 17:08:18 +00:00
|
|
|
public static void main(String[] args) throws Exception {
|
2018-06-23 05:32:41 +00:00
|
|
|
RedefineClassTest_A a = new RedefineClassTest_A();
|
2014-06-02 17:08:18 +00:00
|
|
|
assertTrue(a.Method() == 1);
|
2018-06-23 05:32:41 +00:00
|
|
|
RedefineClassHelper.redefineClass(RedefineClassTest_A.class, newClass);
|
2014-06-02 17:08:18 +00:00
|
|
|
assertTrue(a.Method() == 2);
|
2014-05-28 14:36:32 +00:00
|
|
|
}
|
|
|
|
}
|