This class may be removed in the future. Consider the replacements in JEP 193 'Variable Handles': http://openjdk.java.net/jeps/193
@Override public <T> Class<?> defineClass(Class<T> iClass, String reflectorClassName, byte[] bytecode) { return unsafe.defineClass( reflectorClassName, bytecode, 0, bytecode.length, iClass.getClassLoader(), null); } }
@SuppressWarnings("unchecked") private Class<T> defineClass(String specializedClassName, byte[] specializedClassBytecode) { return (Class<T>) UNSAFE.defineClass( specializedClassName, specializedClassBytecode, 0, specializedClassBytecode.length, prototypeClass.getClassLoader(), prototypeClass.getProtectionDomain() ); }
private Class defineClassImpl(byte[] code, boolean mustBeBootstrap) { ClassLoader loader = null; if (! mustBeBootstrap) { loader = new ClassLoader(null) {}; } Class cl = unsafe.defineClass(className, code, 0, code.length, loader, null); unsafe.ensureClassInitialized(cl); return cl; }
@SuppressWarnings("ClassNewInstance") protected void loadTraceCode(String origName) throws Exception { if (traceCode == null) { String traceName = new ClassReader(traceCode).getClassName().replace('.', '/'); Class<?> clz = unsafe.defineClass(traceName, traceCode, 0, traceCode.length, cl, null); clz.newInstance(); } else { System.err.println("Unable to process trace " + origName); } }
@SuppressWarnings("ClassNewInstance") protected void loadClass(String origName) throws Exception { if (transformedBC != null) { String clzName = new ClassReader(transformedBC).getClassName().replace('.', '/'); Class<?> clz = unsafe.defineClass(clzName, transformedBC, 0, transformedBC.length, cl, null); try { clz.newInstance(); } catch (NoSuchFieldError | NoClassDefFoundError e) { // expected; ignore } } else { System.err.println("Unable to instrument class " + origName); transformedBC = originalBC; } }
Class<?> clazz = getUnsafe().defineClass( "org.apache.flink.TestSerializable", classData, 0, classData.length,
printClassBytes(byteCode); Class<?> definedClass = UnsafeAccess.UNSAFE.defineClass(generatedName, byteCode, 0, byteCode.length, iFace.getClassLoader(), null); return instantiate(definedClass, capacity, waitStrategy);
@Override public Class run() { ClassLoader cl = MAGIC_CLASS_LOADER; return unsafe.defineClass(reuseImplClassName, impl, 0, impl.length, cl, null); } });
@Override public Class run() { ClassLoader cl = MAGIC_CLASS_LOADER; return unsafe.defineClass(reuseImplClassName, impl, 0, impl.length, cl, null); } });
@Override public Class run() { ClassLoader cl = MAGIC_CLASS_LOADER; return unsafe.defineClass(reuseImplClassName, impl, 0, impl.length, cl, null); } });
@Override public Class run() { ClassLoader cl = MAGIC_CLASS_LOADER; return unsafe.defineClass(reuseImplClassName, impl, 0, impl.length, cl, null); } });
/** * Define a class into the current class loader * * @param classLoader to load the class. * @param className of the class to define. * @param bytes byte code for the class * @return the class loaded. */ private static Class defineClass(ClassLoader classLoader, String className, @NotNull byte[] bytes) { return UnsafeMemory.UNSAFE.defineClass(className, bytes, 0, bytes.length, classLoader, null); } }
/** * Define a class into the current class loader * * @param classLoader to load the class. * @param className of the class to define. * @param bytes byte code for the class * @return the class loaded. */ private static Class defineClass(ClassLoader classLoader, String className, @NotNull byte[] bytes) { return UnsafeMemory.UNSAFE.defineClass(className, bytes, 0, bytes.length, classLoader, null); } }
@Override public <T> Class<?> defineClass(Class<T> iClass, String reflectorClassName, byte[] bytecode) { return unsafe.defineClass( reflectorClassName, bytecode, 0, bytecode.length, iClass.getClassLoader(), null); }
@SuppressWarnings("unchecked") private Class<T> defineClass(String specializedClassName, byte[] specializedClassBytecode) { return (Class<T>) UNSAFE.defineClass( specializedClassName, specializedClassBytecode, 0, specializedClassBytecode.length, prototypeClass.getClassLoader(), prototypeClass.getProtectionDomain() ); }
@SuppressWarnings("unchecked") private Class<T> defineClass(String specializedClassName, byte[] specializedClassBytecode) { return (Class<T>) UNSAFE.defineClass( specializedClassName, specializedClassBytecode, 0, specializedClassBytecode.length, prototypeClass.getClassLoader(), prototypeClass.getProtectionDomain() ); }
public Class<?> defineClassX(String className, byte[] b, int off, int len) { if (sunJVM) { return ((Unsafe) sunUnsafe).defineClass(className, b, off, len); } else { return super.defineClass(className, b, off, len); } } }
private Class defineClassImpl(byte[] code, boolean mustBeBootstrap) { ClassLoader loader = null; if (!mustBeBootstrap) { loader = new ClassLoader(null) { }; } Class cl = unsafe.defineClass(className, code, 0, code.length, loader, null); unsafe.ensureClassInitialized(cl); return cl; }
public static <T> Class<T> define(ClassLoader targetClassLoader, String className, byte[] clazzBytes) { return Cast.uncheckedCast(UNSAFE.defineClass(className, clazzBytes, 0, clazzBytes.length, targetClassLoader, null)); } }
private Class createProxy(Class<?> clsToProxy, String proxyName, ClassLoader cl) { String clsName = proxyName.replaceAll("\\.", "/"); try { return cl.loadClass(proxyName); } catch (Exception e) { } try { byte[] proxyBytes = generateProxy(clsToProxy, clsName); return (Class<?>) unsafe.defineClass(proxyName, proxyBytes, 0, proxyBytes.length, cl, this.getClass().getProtectionDomain()); } catch (ProxyGenerationException e) { throw new InternalError(e.toString()); } }