view test/runtime/6626217/Loader2.java @ 12986:1b422ef5288a

8025728: Missing volatile specifier for field G1AllocRegion::_alloc_region Summary: The field G1AllocRegion::_alloc_region needs to be declared volatile as it is used with that intention. Otherwise the compiler may generate the code that reloads the value which might have changed in the meantime, leading to spurious crashes. Reviewed-by: iveresov, simonis, tschatzl Contributed-by: Axel Siebenborn <axel.siebenborn@sap.com>
author tschatzl
date Wed, 23 Oct 2013 10:23:06 +0200
parents 495caa35b1b5
children
line wrap: on
line source

import java.io.ByteArrayInputStream;
import java.io.FileInputStream;
public class Loader2 extends ClassLoader {
  int _recur;
  public void print( String msg ) {
    for( int i=0; i<_recur; i++ )
      System.out.print("  ");
    System.out.println(">>Loader2>> "+msg);
  }

  protected Class findClass2(String name) throws ClassNotFoundException {
    print("Fetching the implementation of "+name);
    int old = _recur;
    try {
      FileInputStream fi = new FileInputStream(name+".impl2");
      byte result[] = new byte[fi.available()];
      fi.read(result);

      print("DefineClass1 on "+name);
      _recur++;
      Class clazz = defineClass(name, result, 0, result.length);
      _recur = old;
      print("Returning newly loaded class.");
      return clazz;
    } catch (Exception e) {
      _recur = old;
      print("Not found on disk.");
      // If we caught an exception, either the class was not found or
      // it was unreadable by our process.
      return null;
      //throw new ClassNotFoundException(e.toString());
    }
  }

  protected synchronized Class loadClass(String name, boolean resolve) throws ClassNotFoundException  {
    // Attempt a disk load first
    Class c = findClass2(name);
    if( c == null ) {
      // check if the class has already been loaded
      print("Checking for prior loaded class "+name);
      c = findLoadedClass(name);
      print("Letting super-loader load "+name);
      int old = _recur;
      _recur++;
      c = super.loadClass(name, false);
      _recur=old;
    }
    if (resolve) { print("Resolving class "+name); resolveClass(c); }
    print("Returning clazz "+c.getClassLoader()+":"+name);
    return c;
  }
}