/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* 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.
*/
/**
* @test
* @bug 4882798
* @summary multi-thread test to exercise sync and contention for adds to transformer registry
* @author Gabriel Adauto, Wily Technology
*
* @run build TransformerManagementThreadAddTests
* @run shell MakeJAR.sh redefineAgent
* @run main/othervm -javaagent:redefineAgent.jar TransformerManagementThreadAddTests TransformerManagementThreadAddTests
*/
{
public static void
throws Throwable {
}
protected void
throws Throwable {
}
/**
* CONFIGURATION FOR TEST
* ----------------------
* Set these variables to different values to test the object that
* manages the transformers.
*
* MIN_TRANS: the minimum number of transformers to add by a thread
* MAX_TRANS: the maximum number of transformers to add by a thread
* There will be a total of MAX_TRANS-MIN_TRANS+1 threads created.
* Each thread will add between MIN_TRANS and MAX_TRANS transformers
* to the manager.
*
* REMOVE_THREADS: the number of threads to run that spend their time
* removing transformers
*/
protected static final boolean LOG_TRANSFORMATIONS = false;
/**
* Field variables
*/
private byte[] fDummyClassBytes;
// fCheckedTransformers is a Vector that is used to verify
// that the transform() function is called in the same
// order in which the transformers were added to the
// TransformerManager. The test currently verifies that all
// transformers for a specific worker thread are in
// increasing order by index value.
private int fFinished;
// Need to use this for synchronization in subclass
/**
* Constructor for TransformerManagementThreadAddTests.
* @param name Name for the test
*/
{
super(name);
fCheckedTransformers = new Vector();
fAddedTransformers = new Vector();
fDummyClassName = "DummyClass";
try
{
}
catch (IOException e)
{
}
}
public void
{
{
}
{
}
// Effective Java - Item 48: Synchronize access to shared mutable data
// Don't use a direct field getter.
{
// Effective Java - Item 51: Don't depend on the thread scheduler
// Use sleep() instead of yield().
try {
} catch (InterruptedException ie) {
}
}
assertTrue(finalCheck());
if (LOG_TRANSFORMATIONS) {
}
}
/**
* Returns the Instrumentation.
* @return Instrumentation the data type with JPLIS calls
*/
{
return fInstrumentation;
}
/**
* Returns the execution thread
* @return ExecuteTransformersThread
*/
{
return fExec;
}
/**
* Sets the execution thread
* @param exec The execution thread to set
*/
{
}
// Effective Java - Item 48: Synchronize access to shared mutable data
// Document a synchronized setter.
protected synchronized void
{
fFinished++;
}
// Effective Java - Item 48: Synchronize access to shared mutable data
// Provide synchronized getter.
protected synchronized boolean
{
return fFinished == TOTAL_THREADS;
}
/**
* Method testCompleted.
* @return boolean
*/
protected boolean
{
// Effective Java - Item 48: Synchronize access to shared mutable data
// Don't use direct field getter.
return getExecThread().isDone();
}
/**
*
*/
protected boolean
{
if (LOG_TRANSFORMATIONS) {
// log the list
}
// check for multiples
}
}
}
}
for (int i = 0; i < j; i++) {
!(
}
}
return true;
}
/**
*
*/
protected void
setUp()
throws Exception
{
super.setUp();
fFinished = 0;
}
/**
*
*/
protected void
tearDown()
throws Exception
{
super.tearDown();
}
/**
* Method executeTransform.
*/
private void
{
try
{
// When the ClassDefinition above is created for the first
// time and every time redefineClasses() below is called,
// the transform() function is called for each registered
// transformer. We only want one complete set of calls to
// be logged in the fCheckedTransformers Vector so we clear
// any calls logged for ClassDefinition above and just use
// the ones logged for redefineClasses() below.
}
catch (ClassNotFoundException e)
{
}
catch (UnmodifiableClassException e)
{
}
}
/**
* Method addTransformerToManager.
* @param threadTransformer
*/
private void
{
}
/**
* Method checkInTransformer.
* @param myClassFileTransformer
*/
private void
{
}
/**
* Method createTransformer.
* @param transformerThread
* @param i
* @return ThreadTransformer
*/
private ThreadTransformer
{
return tt;
}
protected class
extends Thread
{
private boolean fDone = false;
// Effective Java - Item 48: Synchronize access to shared mutable data
// Provide a synchronized getter.
private synchronized boolean isDone() {
return fDone;
}
// Effective Java - Item 48: Synchronize access to shared mutable data
// Provide a synchronized setter.
private synchronized void setIsDone() {
fDone = true;
}
public void
run()
{
while(!threadsDone())
{
}
// Do a final check for good measure
// Effective Java - Item 48: Synchronize access to shared mutable data
// Don't use direct field setter.
setIsDone();
}
}
protected class
extends Thread
{
{
super(name);
}
/**
* Method makeTransformers.
* @param numTransformers
* @return ThreadTransformer[]
*/
private ThreadTransformer[]
{
{
}
return trans;
}
public void
run()
{
{
}
threadFinished(TransformerThread.this);
}
}
/**
* ClassFileTransformer implementation that knows its thread
*/
protected class
{
private final int fIndex;
/**
* Constructor for ThreadTransformer.
*/
super();
}
{
return fName;
}
/**
*
*/
public byte[]
byte[] classfileBuffer)
{
}
}
/**
* Returns the index.
* @return int
*/
public int getIndex()
{
return fIndex;
}
/**
* Returns the thread.
* @return Thread
*/
{
return fThread;
}
}
/**
* DEBUG STUFF
*/
private int NUM_SWITCHES;
/**
* Method printTransformers.
*/
protected void printTransformers()
{
NUM_SWITCHES = 0;
{
{
{
NUM_SWITCHES++;
}
else
}
else
if (i % 5 == 0)
{
}
else
old = t;
}
}
protected String
{
{
}
}
/**
* END DEBUG STUFF
*/
}