jdk/test/java/lang/instrument/TransformerManagementThreadAddTests.java
author dcubed
Mon, 24 Mar 2008 15:14:31 -0700
changeset 273 3d51c181a2e5
parent 271 696ff142e6e6
child 715 f16baef3a20e
permissions -rw-r--r--
6274276: 3/2 java.lang.instrument JAR manifest processing does not remove spaces from class names Summary: Attribute values should be extracted without leading or trailing whitespace. Reviewed-by: ohair, sspitsyn
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
     2
 * Copyright 2003-2004 Sun Microsystems, Inc.  All Rights Reserved.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 * CA 95054 USA or visit www.sun.com if you need additional information or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
 * have any questions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
 * @test
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
 * @bug 4882798
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
 * @summary multi-thread test to exercise sync and contention for adds to transformer registry
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
 * @author Gabriel Adauto, Wily Technology
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
 * @run build TransformerManagementThreadAddTests
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
 * @run shell MakeJAR.sh redefineAgent
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 * @run main/othervm -javaagent:redefineAgent.jar TransformerManagementThreadAddTests TransformerManagementThreadAddTests
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.io.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.lang.instrument.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.security.ProtectionDomain;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import java.util.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
public class TransformerManagementThreadAddTests extends ATestCaseScaffold
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
    public static void
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
    main (String[] args)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
        throws Throwable {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
        ATestCaseScaffold   test = new TransformerManagementThreadAddTests(args[0]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
        test.runTest();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
    protected void
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
    doRunTest()
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
        throws Throwable {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
        testMultiThreadAdds();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
     * CONFIGURATION FOR TEST
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
     * ----------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
     * Set these variables to different values to test the object that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
     * manages the transformers.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
     * MIN_TRANS: the minimum number of transformers to add by a thread
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
     * MAX_TRANS: the maximum number of transformers to add by a thread
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
     *      There will be a total of MAX_TRANS-MIN_TRANS+1 threads created.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
     *      Each thread will add between MIN_TRANS and MAX_TRANS transformers
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
     *      to the manager.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
     * REMOVE_THREADS: the number of threads to run that spend their time
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
     *                  removing transformers
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    protected static final int MIN_TRANS = 33;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    protected static final int MAX_TRANS = 45;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    protected static final int REMOVE_THREADS = 5;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    protected static final boolean LOG_TRANSFORMATIONS = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
     * Field variables
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    protected static final int TOTAL_THREADS = MAX_TRANS - MIN_TRANS + 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    private byte[]          fDummyClassBytes;
270
db5c79396919 6239043: 4/4 TransformerManagementThreadAddTests.java failed
dcubed
parents: 2
diff changeset
    82
    // fCheckedTransformers is a Vector that is used to verify
db5c79396919 6239043: 4/4 TransformerManagementThreadAddTests.java failed
dcubed
parents: 2
diff changeset
    83
    // that the transform() function is called in the same
db5c79396919 6239043: 4/4 TransformerManagementThreadAddTests.java failed
dcubed
parents: 2
diff changeset
    84
    // order in which the transformers were added to the
db5c79396919 6239043: 4/4 TransformerManagementThreadAddTests.java failed
dcubed
parents: 2
diff changeset
    85
    // TransformerManager. The test currently verifies that all
db5c79396919 6239043: 4/4 TransformerManagementThreadAddTests.java failed
dcubed
parents: 2
diff changeset
    86
    // transformers for a specific worker thread are in
db5c79396919 6239043: 4/4 TransformerManagementThreadAddTests.java failed
dcubed
parents: 2
diff changeset
    87
    // increasing order by index value.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    private Vector              fCheckedTransformers;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    private Instrumentation fInstrumentation;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    private int             fFinished;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
    private ExecuteTransformersThread fExec;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    // Need to use this for synchronization in subclass
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    protected Vector            fAddedTransformers;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    private String          fDummyClassName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
     * Constructor for TransformerManagementThreadAddTests.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
     * @param name  Name for the test
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    public TransformerManagementThreadAddTests(String name)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
        super(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
        fCheckedTransformers = new Vector();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
        fAddedTransformers = new Vector();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
        fDummyClassName = "DummyClass";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
        String resourceName = "DummyClass.class";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
        File f = new File(System.getProperty("test.classes", "."), resourceName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
        System.out.println("Reading test class from " + f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
        try
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
            InputStream redefineStream = new FileInputStream(f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
            fDummyClassBytes = NamedBuffer.loadBufferFromStream(redefineStream);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
        catch (IOException e)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
            fail("Could not load the class: "+resourceName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
    public void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
    testMultiThreadAdds()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
        TransformerThread[] threads = new TransformerThread[TOTAL_THREADS];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
        for (int i = MIN_TRANS; i <= MAX_TRANS; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
            int index = i - MIN_TRANS;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
            threads[index] = new TransformerThread("Trans"+prettyNum(index,2), i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
        ExecuteTransformersThread exec = new ExecuteTransformersThread();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
        exec.start();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
        for (int i = threads.length - 1; i >= 0; i--)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
            threads[i].start();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
271
696ff142e6e6 4926961: 4/4 TransformerManagementThreadRemoveTests hangs
dcubed
parents: 270
diff changeset
   140
        // Effective Java - Item 48: Synchronize access to shared mutable data
696ff142e6e6 4926961: 4/4 TransformerManagementThreadRemoveTests hangs
dcubed
parents: 270
diff changeset
   141
        // Don't use a direct field getter.
696ff142e6e6 4926961: 4/4 TransformerManagementThreadRemoveTests hangs
dcubed
parents: 270
diff changeset
   142
        while (!exec.isDone())
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
        {
271
696ff142e6e6 4926961: 4/4 TransformerManagementThreadRemoveTests hangs
dcubed
parents: 270
diff changeset
   144
            // Effective Java - Item 51: Don't depend on the thread scheduler
696ff142e6e6 4926961: 4/4 TransformerManagementThreadRemoveTests hangs
dcubed
parents: 270
diff changeset
   145
            // Use sleep() instead of yield().
696ff142e6e6 4926961: 4/4 TransformerManagementThreadRemoveTests hangs
dcubed
parents: 270
diff changeset
   146
            try {
696ff142e6e6 4926961: 4/4 TransformerManagementThreadRemoveTests hangs
dcubed
parents: 270
diff changeset
   147
                Thread.sleep(500);
696ff142e6e6 4926961: 4/4 TransformerManagementThreadRemoveTests hangs
dcubed
parents: 270
diff changeset
   148
            } catch (InterruptedException ie) {
696ff142e6e6 4926961: 4/4 TransformerManagementThreadRemoveTests hangs
dcubed
parents: 270
diff changeset
   149
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
        assertTrue(finalCheck());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
        if (LOG_TRANSFORMATIONS) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
            printTransformers();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
     * Returns the Instrumentation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
     * @return Instrumentation  the data type with JPLIS calls
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
    public Instrumentation getInstrumentation()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
        return fInstrumentation;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
     * Returns the execution thread
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
     * @return ExecuteTransformersThread
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
    protected ExecuteTransformersThread getExecThread()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
        return fExec;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
     * Sets the execution thread
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
     * @param exec The execution thread to set
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
    protected void setExecThread(ExecuteTransformersThread exec)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
        this.fExec = exec;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
271
696ff142e6e6 4926961: 4/4 TransformerManagementThreadRemoveTests hangs
dcubed
parents: 270
diff changeset
   185
    // Effective Java - Item 48: Synchronize access to shared mutable data
696ff142e6e6 4926961: 4/4 TransformerManagementThreadRemoveTests hangs
dcubed
parents: 270
diff changeset
   186
    // Document a synchronized setter.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
    protected synchronized void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
    threadFinished(Thread t)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
        fFinished++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
271
696ff142e6e6 4926961: 4/4 TransformerManagementThreadRemoveTests hangs
dcubed
parents: 270
diff changeset
   193
    // Effective Java - Item 48: Synchronize access to shared mutable data
696ff142e6e6 4926961: 4/4 TransformerManagementThreadRemoveTests hangs
dcubed
parents: 270
diff changeset
   194
    // Provide synchronized getter.
696ff142e6e6 4926961: 4/4 TransformerManagementThreadRemoveTests hangs
dcubed
parents: 270
diff changeset
   195
    protected synchronized boolean
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
    threadsDone()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
        return fFinished == TOTAL_THREADS;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
     * Method testCompleted.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
     * @return boolean
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
    protected boolean
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
    testCompleted()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
    {
271
696ff142e6e6 4926961: 4/4 TransformerManagementThreadRemoveTests hangs
dcubed
parents: 270
diff changeset
   208
        // Effective Java - Item 48: Synchronize access to shared mutable data
696ff142e6e6 4926961: 4/4 TransformerManagementThreadRemoveTests hangs
dcubed
parents: 270
diff changeset
   209
        // Don't use direct field getter.
696ff142e6e6 4926961: 4/4 TransformerManagementThreadRemoveTests hangs
dcubed
parents: 270
diff changeset
   210
        return getExecThread().isDone();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
    protected boolean
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
    finalCheck()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
        if (LOG_TRANSFORMATIONS) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
            // log the list
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
            for (int x = 0; x < fCheckedTransformers.size(); x++ ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
                System.out.println(x + "\t\t" + fCheckedTransformers.get(x));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
            System.out.println();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
            System.out.println();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
            // check for multiples
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
            for (int x = 0; x < fCheckedTransformers.size(); x++ ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
                Object current = fCheckedTransformers.get(x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
                for ( int y = x + 1; y < fCheckedTransformers.size(); y++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
                    Object running = fCheckedTransformers.get(y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
                    if ( current.equals(running) ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
                        System.out.println(x + "\t" + y + " \t" + "FOUND DUPLICATE: " + current);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
        for (int j = 1; j < fCheckedTransformers.size(); j++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
            ThreadTransformer transformer = (ThreadTransformer)fCheckedTransformers.get(j);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
            for (int i = 0; i < j; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
                ThreadTransformer currTrans = (ThreadTransformer)fCheckedTransformers.get(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
                assertTrue(currTrans + " incorrectly appeared before " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
                           transformer + " i=" + i + " j=" + j + " size=" +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
                           fCheckedTransformers.size(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
                           !(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
                             currTrans.getThread().equals(transformer.getThread()) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
                             currTrans.getIndex() > transformer.getIndex()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
    protected void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
    setUp()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
        throws Exception
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
        super.setUp();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
        fFinished = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
        assertTrue(MIN_TRANS < MAX_TRANS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
        fInstrumentation = InstrumentationHandoff.getInstrumentationOrThrow();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
    protected void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
    tearDown()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
        throws Exception
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
        super.tearDown();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
     * Method executeTransform.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
    private void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
    executeTransform()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
        try
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
            ClassDefinition cd = new ClassDefinition(DummyClass.class, fDummyClassBytes);
270
db5c79396919 6239043: 4/4 TransformerManagementThreadAddTests.java failed
dcubed
parents: 2
diff changeset
   289
db5c79396919 6239043: 4/4 TransformerManagementThreadAddTests.java failed
dcubed
parents: 2
diff changeset
   290
            // When the ClassDefinition above is created for the first
db5c79396919 6239043: 4/4 TransformerManagementThreadAddTests.java failed
dcubed
parents: 2
diff changeset
   291
            // time and every time redefineClasses() below is called,
db5c79396919 6239043: 4/4 TransformerManagementThreadAddTests.java failed
dcubed
parents: 2
diff changeset
   292
            // the transform() function is called for each registered
db5c79396919 6239043: 4/4 TransformerManagementThreadAddTests.java failed
dcubed
parents: 2
diff changeset
   293
            // transformer. We only want one complete set of calls to
db5c79396919 6239043: 4/4 TransformerManagementThreadAddTests.java failed
dcubed
parents: 2
diff changeset
   294
            // be logged in the fCheckedTransformers Vector so we clear
db5c79396919 6239043: 4/4 TransformerManagementThreadAddTests.java failed
dcubed
parents: 2
diff changeset
   295
            // any calls logged for ClassDefinition above and just use
db5c79396919 6239043: 4/4 TransformerManagementThreadAddTests.java failed
dcubed
parents: 2
diff changeset
   296
            // the ones logged for redefineClasses() below.
db5c79396919 6239043: 4/4 TransformerManagementThreadAddTests.java failed
dcubed
parents: 2
diff changeset
   297
            fCheckedTransformers.clear();
db5c79396919 6239043: 4/4 TransformerManagementThreadAddTests.java failed
dcubed
parents: 2
diff changeset
   298
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
            getInstrumentation().redefineClasses(new ClassDefinition[]{ cd });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
        catch (ClassNotFoundException e)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
            fail("Could not find the class: "+DummyClass.class.getName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
        catch (UnmodifiableClassException e)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
            fail("Could not modify the class: "+DummyClass.class.getName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
     * Method addTransformerToManager.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
     * @param threadTransformer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
    private void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
    addTransformerToManager(ThreadTransformer threadTransformer)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
        getInstrumentation().addTransformer(threadTransformer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
        fAddedTransformers.add(threadTransformer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
     * Method checkInTransformer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
     * @param myClassFileTransformer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
    private void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
    checkInTransformer(ThreadTransformer transformer)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
        fCheckedTransformers.add(transformer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
     * Method createTransformer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
     * @param transformerThread
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
     * @param i
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
     * @return ThreadTransformer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
    private ThreadTransformer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
    createTransformer(TransformerThread thread, int index)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
        ThreadTransformer tt = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
        tt = new ThreadTransformer(thread, index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
        return tt;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
    protected class
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
    ExecuteTransformersThread
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
        extends Thread
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
        private boolean fDone = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
271
696ff142e6e6 4926961: 4/4 TransformerManagementThreadRemoveTests hangs
dcubed
parents: 270
diff changeset
   355
        // Effective Java - Item 48: Synchronize access to shared mutable data
696ff142e6e6 4926961: 4/4 TransformerManagementThreadRemoveTests hangs
dcubed
parents: 270
diff changeset
   356
        // Provide a synchronized getter.
696ff142e6e6 4926961: 4/4 TransformerManagementThreadRemoveTests hangs
dcubed
parents: 270
diff changeset
   357
        private synchronized boolean isDone() {
696ff142e6e6 4926961: 4/4 TransformerManagementThreadRemoveTests hangs
dcubed
parents: 270
diff changeset
   358
            return fDone;
696ff142e6e6 4926961: 4/4 TransformerManagementThreadRemoveTests hangs
dcubed
parents: 270
diff changeset
   359
        }
696ff142e6e6 4926961: 4/4 TransformerManagementThreadRemoveTests hangs
dcubed
parents: 270
diff changeset
   360
696ff142e6e6 4926961: 4/4 TransformerManagementThreadRemoveTests hangs
dcubed
parents: 270
diff changeset
   361
        // Effective Java - Item 48: Synchronize access to shared mutable data
696ff142e6e6 4926961: 4/4 TransformerManagementThreadRemoveTests hangs
dcubed
parents: 270
diff changeset
   362
        // Provide a synchronized setter.
696ff142e6e6 4926961: 4/4 TransformerManagementThreadRemoveTests hangs
dcubed
parents: 270
diff changeset
   363
        private synchronized void setIsDone() {
696ff142e6e6 4926961: 4/4 TransformerManagementThreadRemoveTests hangs
dcubed
parents: 270
diff changeset
   364
            fDone = true;
696ff142e6e6 4926961: 4/4 TransformerManagementThreadRemoveTests hangs
dcubed
parents: 270
diff changeset
   365
        }
696ff142e6e6 4926961: 4/4 TransformerManagementThreadRemoveTests hangs
dcubed
parents: 270
diff changeset
   366
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
        public void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
        run()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
            while(!threadsDone())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
                executeTransform();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
            // Do a final check for good measure
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
            executeTransform();
271
696ff142e6e6 4926961: 4/4 TransformerManagementThreadRemoveTests hangs
dcubed
parents: 270
diff changeset
   377
            // Effective Java - Item 48: Synchronize access to shared mutable data
696ff142e6e6 4926961: 4/4 TransformerManagementThreadRemoveTests hangs
dcubed
parents: 270
diff changeset
   378
            // Don't use direct field setter.
696ff142e6e6 4926961: 4/4 TransformerManagementThreadRemoveTests hangs
dcubed
parents: 270
diff changeset
   379
            setIsDone();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
    protected class
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
    TransformerThread
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
        extends Thread
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
        private final ThreadTransformer[] fThreadTransformers;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
        TransformerThread(String name, int numTransformers)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
            super(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
            fThreadTransformers = makeTransformers(numTransformers);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
         * Method makeTransformers.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
         * @param numTransformers
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
         * @return ThreadTransformer[]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
        private ThreadTransformer[]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
        makeTransformers(int numTransformers)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
            ThreadTransformer[] trans = new ThreadTransformer[numTransformers];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
            for (int i = 0; i < trans.length; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
                trans[i] = createTransformer(TransformerThread.this, i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
            return trans;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
        public void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
        run()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
            for (int i = 0; i < fThreadTransformers.length; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
                addTransformerToManager(fThreadTransformers[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
            threadFinished(TransformerThread.this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
     * ClassFileTransformer implementation that knows its thread
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
    protected class
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
    ThreadTransformer extends SimpleIdentityTransformer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
        private final String    fName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
        private final int       fIndex;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
        private final Thread    fThread;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
         * Constructor for ThreadTransformer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
        public ThreadTransformer(Thread thread, int index) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
            super();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
            fThread = thread;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
            fIndex = index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
            fName = "TT["+fThread.getName()+"]["+prettyNum(fIndex,3)+"]";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
        public String toString()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
            return fName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
        public byte[]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
        transform(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
            ClassLoader loader,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
            String className,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
            Class<?> classBeingRedefined,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
            ProtectionDomain domain,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
            byte[] classfileBuffer)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
            if ( className.equals(TransformerManagementThreadAddTests.this.fDummyClassName) ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
                checkInTransformer(ThreadTransformer.this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
            return super.transform(    loader,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
                                        className,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
                                        classBeingRedefined,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
                                        domain,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
                                        classfileBuffer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
         * Returns the index.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
         * @return int
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
        public int getIndex()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
            return fIndex;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
         * Returns the thread.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
         * @return Thread
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
        public Thread getThread()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
            return fThread;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
     * DEBUG STUFF
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
    private int NUM_SWITCHES;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
     * Method printTransformers.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
    protected void printTransformers()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
        NUM_SWITCHES = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
        Iterator trans = fCheckedTransformers.iterator();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
        ThreadTransformer old = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
        StringBuffer buf = new StringBuffer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
        for (int i = 1; trans.hasNext(); i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
            ThreadTransformer t = (ThreadTransformer)trans.next();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
            buf.append(t.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
            if (old != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
                if (!old.getThread().equals(t.getThread()))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
                {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
                    NUM_SWITCHES++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
                    buf.append("*");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
                else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
                { buf.append(" "); }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
            else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
            { buf.append(" "); }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
            if (i % 5 == 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
                buf.append("\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
            else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
            { buf.append(" "); }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
            old = t;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
        System.out.println(buf);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
        System.out.println("\nNumber of transitions from one thread to another: "+NUM_SWITCHES);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
    protected String
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
    prettyNum(int n, int numSize)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
        StringBuffer num = new StringBuffer(Integer.toString(n));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
        int size = num.length();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
        for (int i = 0; i < numSize - size; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
            num.insert(0, "0");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
        return num.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
     * END DEBUG STUFF
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
}