0N/A/*
2362N/A * Copyright (c) 2005, 2007, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
0N/A * published by the Free Software Foundation.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A
0N/A/**
0N/A * @test
0N/A * @bug 6331574
0N/A * @summary test isModifiableClass
0N/A * @author Robert Field, Sun Microsystems
0N/A *
0N/A * @run build IsModifiableClassApp IsModifiableClassAgent
0N/A * @run shell MakeJAR3.sh IsModifiableClassAgent 'Can-Retransform-Classes: true'
0N/A * @run main/othervm -javaagent:IsModifiableClassAgent.jar IsModifiableClassApp
0N/A */
0N/Aimport java.lang.instrument.*;
0N/A
0N/Apublic class IsModifiableClassAgent
0N/A{
0N/A public static boolean fail = false;
0N/A public static boolean completed = false;
0N/A
0N/A public static void
0N/A premain( String agentArgs,
0N/A Instrumentation instrumentation)
0N/A {
0N/A System.out.println("IsModifiableClassAgent started");
0N/A
0N/A Class[] allClasses = instrumentation.getAllLoadedClasses();
0N/A int modCount = 0;
0N/A int unmodCount = 0;
0N/A
0N/A for (int i = 0; i < allClasses.length; i++)
0N/A {
0N/A Class klass = allClasses[i];
0N/A boolean isMod = instrumentation.isModifiableClass(klass);
0N/A if (isMod && klass.isArray()) {
0N/A System.err.println("Error: array class returned as modifiable: " + klass);
0N/A fail = true;
0N/A }
0N/A if (isMod && klass.isPrimitive()) {
0N/A System.err.println("Error: primitive class returned as modifiable: " + klass);
0N/A fail = true;
0N/A }
0N/A try {
0N/A instrumentation.retransformClasses(klass);
0N/A if (!isMod) {
0N/A System.err.println("Error: unmodifiable class retransformable: " + klass);
0N/A fail = true;
0N/A }
0N/A } catch (UnmodifiableClassException e) {
0N/A if (isMod) {
0N/A System.err.println("Error: modifiable class not retransformable: " + klass);
0N/A System.err.println(" exception: " + e);
0N/A fail = true;
0N/A }
0N/A } catch (Throwable e) {
0N/A System.err.println("Error: bad return from retransform: " + klass);
0N/A System.err.println(" ERROR: " + e);
0N/A fail = true;
0N/A }
0N/A if (isMod) {
0N/A ++modCount;
0N/A } else {
0N/A ++unmodCount;
0N/A }
0N/A }
0N/A System.out.println("modifiable: " + modCount + ". unmodifiable: " + unmodCount);
0N/A completed = true;
0N/A }
0N/A}