dynclass
This commit is contained in:
@@ -92,7 +92,8 @@ public class AsmMethodBean {
|
||||
return null;
|
||||
}
|
||||
Parameter[] ps = method == null ? null : method.getParameters();
|
||||
String[] rs = new String[params.size()];
|
||||
// params包含了throws, size()可能比ps.length大
|
||||
String[] rs = new String[ps == null ? params.size() : ps.length];
|
||||
for (int i = 0; i < rs.length; i++) {
|
||||
Param pann = ps == null ? null : ps[i].getAnnotation(Param.class);
|
||||
rs[i] = pann == null ? params.get(i).getName() : pann.value();
|
||||
|
||||
@@ -118,8 +118,7 @@ public abstract class AsmMethodBoost<T> {
|
||||
* @param newDynName 动态新类名
|
||||
* @param fieldPrefix 动态字段的前缀
|
||||
*/
|
||||
public void doAfterMethods(
|
||||
RedkaleClassLoader classLoader, ClassWriter cw, String newDynName, String fieldPrefix) {}
|
||||
public void doAfterMethods(RedkaleClassLoader classLoader, ClassWriter cw, String newDynName, String fieldPrefix) {}
|
||||
|
||||
/**
|
||||
* 处理所有动态方法后调用
|
||||
@@ -437,14 +436,23 @@ public abstract class AsmMethodBoost<T> {
|
||||
// 返回的List中参数列表可能会比方法参数量多,因为方法内的临时变量也会存入list中, 所以需要list的元素集合比方法的参数多
|
||||
static Map<String, AsmMethodBean> getMethodParamNames(Map<String, AsmMethodBean> map, Class clazz) {
|
||||
String n = clazz.getName();
|
||||
InputStream in = clazz.getResourceAsStream(n.substring(n.lastIndexOf('.') + 1) + ".class");
|
||||
if (in == null) {
|
||||
return map;
|
||||
byte[] bs = RedkaleClassLoader.getDynClassBytes(n);
|
||||
if (bs == null) {
|
||||
InputStream in = clazz.getResourceAsStream(n.substring(n.lastIndexOf('.') + 1) + ".class");
|
||||
if (in == null) {
|
||||
return map;
|
||||
}
|
||||
try {
|
||||
bs = Utility.readBytesThenClose(in);
|
||||
} catch (Exception e) {
|
||||
// do nothing
|
||||
}
|
||||
}
|
||||
try {
|
||||
new ClassReader(Utility.readBytesThenClose(in))
|
||||
.accept(new MethodParamClassVisitor(Opcodes.ASM6, clazz, map), 0);
|
||||
} catch (Exception e) { // 无需理会
|
||||
new ClassReader(bs).accept(new MethodParamClassVisitor(Opcodes.ASM6, clazz, map), 0);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
// do nothing
|
||||
}
|
||||
Class superClass = clazz.getSuperclass();
|
||||
if (superClass == null || superClass == Object.class) { // 接口的getSuperclass为null
|
||||
|
||||
@@ -143,15 +143,14 @@ class AppConfig {
|
||||
if (cacheClasses == null) {
|
||||
this.classLoader = new RedkaleClassLoader(currClassLoader);
|
||||
} else {
|
||||
this.classLoader = new RedkaleClassLoader.RedkaleCacheClassLoader(
|
||||
RedkaleClassLoader.getRedkaleClassLoader(currClassLoader), cacheClasses);
|
||||
this.classLoader = new RedkaleClassLoader.RedkaleCacheClassLoader(currClassLoader, cacheClasses);
|
||||
}
|
||||
Thread.currentThread().setContextClassLoader(this.classLoader);
|
||||
}
|
||||
if (compileMode || this.classLoader instanceof RedkaleClassLoader.RedkaleCacheClassLoader) {
|
||||
this.serverClassLoader = this.classLoader;
|
||||
} else {
|
||||
//this.serverClassLoader = RedkaleClassLoader.getRedkaleClassLoader(this.classLoader);
|
||||
// this.serverClassLoader = RedkaleClassLoader.getRedkaleClassLoader(this.classLoader);
|
||||
this.serverClassLoader = this.classLoader;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -828,7 +828,7 @@ public final class Application {
|
||||
|
||||
ExecutorService clientWorkExecutor = this.workExecutor;
|
||||
if (executorName.contains("VirtualExecutor") || executorName.contains("PerTaskExecutor")) {
|
||||
executorLog.append(", clientWorkExecutor: [workExecutor]");
|
||||
executorLog.append(", clientWorkExecutor: [virtual]");
|
||||
} else {
|
||||
// 给所有client给一个新的默认ExecutorService
|
||||
int clientThreads = executorConf.getIntValue("clients", WorkThread.DEFAULT_WORK_POOL_SIZE);
|
||||
|
||||
@@ -71,8 +71,7 @@ public abstract class JsonDynEncoder<T> extends ObjectEncoder<JsonWriter, T> {
|
||||
+ clazz.getName().replace('.', '_').replace('$', '_') + "_" + factory.getFeatures() + "_"
|
||||
+ Utility.md5Hex(elementb.toString()); // tiny必须要加上, 同一个类会有多个字段定制Convert
|
||||
try {
|
||||
Class clz = loader.findDynClass(newDynName.replace('/', '.'));
|
||||
Class newClazz = clz == null ? loader.loadClass(newDynName.replace('/', '.')) : clz;
|
||||
Class newClazz = loader.loadClass(newDynName.replace('/', '.'));
|
||||
JsonDynEncoder resultEncoder =
|
||||
(JsonDynEncoder) newClazz.getConstructor(JsonFactory.class, Type.class, ObjectEncoder.class)
|
||||
.newInstance(factory, clazz, selfObjEncoder);
|
||||
@@ -681,7 +680,6 @@ public abstract class JsonDynEncoder<T> extends ObjectEncoder<JsonWriter, T> {
|
||||
// ------------------------------------------------------------------------------
|
||||
byte[] bytes = cw.toByteArray();
|
||||
Class<?> newClazz = loader.loadClass(newDynName.replace('/', '.'), bytes);
|
||||
loader.putDynClass(newDynName.replace('/', '.'), bytes, newClazz);
|
||||
RedkaleClassLoader.putReflectionDeclaredConstructors(
|
||||
newClazz, newDynName.replace('/', '.'), JsonFactory.class, Type.class);
|
||||
try {
|
||||
|
||||
@@ -74,8 +74,7 @@ public abstract class ProtobufDynEncoder<T> extends ProtobufObjectEncoder<T> {
|
||||
+ clazz.getName().replace('.', '_').replace('$', '_') + "_" + factory.getFeatures() + "_"
|
||||
+ Utility.md5Hex(elementb.toString()); // tiny必须要加上, 同一个类会有多个字段定制Convert
|
||||
try {
|
||||
Class clz = classLoader.findDynClass(newDynName.replace('/', '.'));
|
||||
Class newClazz = clz == null ? classLoader.loadClass(newDynName.replace('/', '.')) : clz;
|
||||
Class newClazz = classLoader.loadClass(newDynName.replace('/', '.'));
|
||||
ProtobufDynEncoder resultEncoder = (ProtobufDynEncoder)
|
||||
newClazz.getConstructor(ProtobufFactory.class, Type.class, ProtobufObjectEncoder.class)
|
||||
.newInstance(factory, clazz, selfObjEncoder);
|
||||
@@ -322,7 +321,6 @@ public abstract class ProtobufDynEncoder<T> extends ProtobufObjectEncoder<T> {
|
||||
|
||||
byte[] bytes = cw.toByteArray();
|
||||
Class<ProtobufDynEncoder> newClazz = classLoader.loadClass(newDynName.replace('/', '.'), bytes);
|
||||
classLoader.putDynClass(newDynName.replace('/', '.'), bytes, newClazz);
|
||||
RedkaleClassLoader.putReflectionDeclaredConstructors(newClazz, newDynName.replace('/', '.'));
|
||||
try {
|
||||
ProtobufDynEncoder resultEncoder = (ProtobufDynEncoder)
|
||||
|
||||
@@ -328,7 +328,6 @@ public class MessageAsmMethodBoost extends AsmMethodBoost {
|
||||
consumerBytes.forEach((innerFullName, bytes) -> {
|
||||
String clzName = innerFullName.replace('/', '.');
|
||||
Class clazz = classLoader.loadClass(clzName, bytes);
|
||||
classLoader.putDynClass(clzName, bytes, clazz);
|
||||
RedkaleClassLoader.putReflectionPublicConstructors(clazz, clzName);
|
||||
AnnotationVisitor av2 =
|
||||
av1.visitAnnotation(null, org.redkale.asm.Type.getDescriptor(DynForMessaged.class));
|
||||
|
||||
@@ -459,7 +459,6 @@ public class MessageModuleEngine extends ModuleEngine {
|
||||
try {
|
||||
String clzName = innerFullName.replace('/', '.');
|
||||
Class<? extends MessageConsumer> clazz = classLoader.loadClass(clzName, bytes);
|
||||
classLoader.putDynClass(clzName, bytes, clazz);
|
||||
RedkaleClassLoader.putReflectionPublicConstructors(clazz, clzName);
|
||||
MessageConsumer consumer = (MessageConsumer) clazz.getConstructors()[0].newInstance(service);
|
||||
addMessageConsumer(consumer);
|
||||
|
||||
@@ -110,9 +110,7 @@ public class HttpContext extends Context {
|
||||
+ handlerClass.getName().replace('.', '/').replace('$', '_');
|
||||
RedkaleClassLoader classLoader = RedkaleClassLoader.getRedkaleClassLoader();
|
||||
try {
|
||||
Class clz = classLoader.findDynClass(newDynName.replace('/', '.'));
|
||||
Class newHandlerClazz = clz == null ? classLoader.loadClass(newDynName.replace('/', '.')) : clz;
|
||||
return Creator.create(newHandlerClazz);
|
||||
return (Creator<H>) Creator.create(classLoader.loadClass(newDynName.replace('/', '.')));
|
||||
} catch (Throwable ex) {
|
||||
// do nothing
|
||||
}
|
||||
@@ -214,7 +212,6 @@ public class HttpContext extends Context {
|
||||
cw.visitEnd();
|
||||
byte[] bytes = cw.toByteArray();
|
||||
Class<CompletionHandler> newClazz = classLoader.loadClass(newDynName.replace('/', '.'), bytes);
|
||||
classLoader.putDynClass(newDynName.replace('/', '.'), bytes, newClazz);
|
||||
return (Creator<H>) Creator.create(newClazz);
|
||||
}
|
||||
|
||||
|
||||
@@ -564,10 +564,10 @@ public class HttpServlet extends Servlet<HttpContext, HttpRequest, HttpResponse>
|
||||
final String newDynName = "org/redkaledyn/http/servlet/action/_DynHttpActionServlet__"
|
||||
+ this.getClass().getName().replace('.', '_').replace('$', '_') + "__" + method.getName() + tmpps;
|
||||
try {
|
||||
Class clz = classLoader.findDynClass(newDynName.replace('/', '.'));
|
||||
Class newClazz = clz == null ? classLoader.loadClass(newDynName.replace('/', '.')) : clz;
|
||||
HttpServlet instance =
|
||||
(HttpServlet) newClazz.getDeclaredConstructor().newInstance();
|
||||
HttpServlet instance = (HttpServlet) classLoader
|
||||
.loadClass(newDynName.replace('/', '.'))
|
||||
.getDeclaredConstructor()
|
||||
.newInstance();
|
||||
instance.getClass().getField("_factServlet").set(instance, this);
|
||||
return instance;
|
||||
} catch (Throwable ex) {
|
||||
@@ -627,7 +627,6 @@ public class HttpServlet extends Servlet<HttpContext, HttpRequest, HttpResponse>
|
||||
// ------------------------------------------------------------------------------
|
||||
byte[] bytes = cw.toByteArray();
|
||||
Class<?> newClazz = classLoader.loadClass(newDynName.replace('/', '.'), bytes);
|
||||
classLoader.putDynClass(newDynName.replace('/', '.'), bytes, newClazz);
|
||||
RedkaleClassLoader.putReflectionDeclaredConstructors(newClazz, newDynName.replace('/', '.'));
|
||||
try {
|
||||
HttpServlet instance =
|
||||
@@ -636,7 +635,7 @@ public class HttpServlet extends Servlet<HttpContext, HttpRequest, HttpResponse>
|
||||
field.set(instance, this);
|
||||
RedkaleClassLoader.putReflectionField(newDynName.replace('/', '.'), field);
|
||||
NonBlocking non = method.getAnnotation(NonBlocking.class);
|
||||
instance._nonBlocking = typeNonBlocking ? (non == null ? typeNonBlocking : non.value()) : false;
|
||||
instance._nonBlocking = typeNonBlocking && (non == null ? typeNonBlocking : non.value());
|
||||
return instance;
|
||||
} catch (Exception ex) {
|
||||
throw new HttpException(ex);
|
||||
|
||||
@@ -455,10 +455,7 @@ public final class Rest {
|
||||
final String newDynConsumerSimpleName = "_DynRestOnMessageConsumer";
|
||||
final String newDynConsumerFullName = newDynName + "$" + newDynConsumerSimpleName;
|
||||
try {
|
||||
Class clz = classLoader.findDynClass(newDynName.replace('/', '.'));
|
||||
if (clz == null) {
|
||||
clz = classLoader.loadClass(newDynName.replace('/', '.'));
|
||||
}
|
||||
Class clz = classLoader.loadClass(newDynName.replace('/', '.'));
|
||||
T servlet = (T) clz.getDeclaredConstructor().newInstance();
|
||||
Map<String, Annotation[]> msgclassToAnnotations = new HashMap<>();
|
||||
for (int i = 0; i < messageMethods.size(); i++) { // _DyncXXXWebSocketMessage 子消息List
|
||||
@@ -899,8 +896,7 @@ public final class Rest {
|
||||
}
|
||||
cw2.visitEnd();
|
||||
byte[] bytes = cw2.toByteArray();
|
||||
Class cz = classLoader.loadClass((newDynSuperMessageFullName).replace('/', '.'), bytes);
|
||||
classLoader.putDynClass((newDynSuperMessageFullName).replace('/', '.'), bytes, cz);
|
||||
classLoader.loadClass((newDynSuperMessageFullName).replace('/', '.'), bytes);
|
||||
}
|
||||
|
||||
if (wildcardMethod == null) { // _DynXXXWebSocketMessage class
|
||||
@@ -957,8 +953,7 @@ public final class Rest {
|
||||
}
|
||||
cw2.visitEnd();
|
||||
byte[] bytes = cw2.toByteArray();
|
||||
Class cz = classLoader.loadClass(newDynMessageFullName.replace('/', '.'), bytes);
|
||||
classLoader.putDynClass(newDynMessageFullName.replace('/', '.'), bytes, cz);
|
||||
classLoader.loadClass(newDynMessageFullName.replace('/', '.'), bytes);
|
||||
}
|
||||
|
||||
{ // _DynXXXWebSocket class
|
||||
@@ -1000,8 +995,7 @@ public final class Rest {
|
||||
}
|
||||
cw2.visitEnd();
|
||||
byte[] bytes = cw2.toByteArray();
|
||||
Class cz = classLoader.loadClass(newDynWebSokcetFullName.replace('/', '.'), bytes);
|
||||
classLoader.putDynClass(newDynWebSokcetFullName.replace('/', '.'), bytes, cz);
|
||||
classLoader.loadClass(newDynWebSokcetFullName.replace('/', '.'), bytes);
|
||||
}
|
||||
|
||||
{ // _DynRestOnMessageConsumer class
|
||||
@@ -1108,14 +1102,12 @@ public final class Rest {
|
||||
}
|
||||
cw2.visitEnd();
|
||||
byte[] bytes = cw2.toByteArray();
|
||||
Class cz = classLoader.loadClass(newDynConsumerFullName.replace('/', '.'), bytes);
|
||||
classLoader.putDynClass(newDynConsumerFullName.replace('/', '.'), bytes, cz);
|
||||
classLoader.loadClass(newDynConsumerFullName.replace('/', '.'), bytes);
|
||||
}
|
||||
cw.visitEnd();
|
||||
|
||||
byte[] bytes = cw.toByteArray();
|
||||
Class<?> newClazz = classLoader.loadClass(newDynName.replace('/', '.'), bytes);
|
||||
classLoader.putDynClass(newDynName.replace('/', '.'), bytes, newClazz);
|
||||
RedkaleClassLoader.putReflectionDeclaredConstructors(newClazz, newDynName.replace('/', '.'));
|
||||
JsonFactory.root().loadDecoder(newClazz.getAnnotation(RestDyn.class).types()[2]); // 固定Message类
|
||||
|
||||
@@ -1301,10 +1293,7 @@ public final class Rest {
|
||||
+ (namePostfix.isEmpty() ? "" : ("_" + namePostfix) + "DynServlet");
|
||||
|
||||
try {
|
||||
Class newClazz = classLoader.findClass(newDynName.replace('/', '.'));
|
||||
if (newClazz == null) {
|
||||
newClazz = classLoader.loadClass(newDynName.replace('/', '.'));
|
||||
}
|
||||
Class newClazz = classLoader.loadClass(newDynName.replace('/', '.'));
|
||||
T obj = (T) newClazz.getDeclaredConstructor().newInstance();
|
||||
|
||||
final String defModuleName = getWebModuleNameLowerCase(serviceType);
|
||||
@@ -4234,16 +4223,15 @@ public final class Rest {
|
||||
byte[] bytes = cw.toByteArray();
|
||||
classLoader.addDynClass(newDynName.replace('/', '.'), bytes);
|
||||
try {
|
||||
Class<?> newClazz = classLoader.findClass(newDynName.replace('/', '.'));
|
||||
Class<?> newClazz = classLoader.loadClass(newDynName.replace('/', '.'));
|
||||
innerClassBytesMap.forEach((n, bs) -> {
|
||||
try {
|
||||
classLoader.putDynClass(n, bs, classLoader.findClass(n));
|
||||
classLoader.loadClass(n, bs);
|
||||
RedkaleClassLoader.putReflectionClass(n);
|
||||
} catch (Exception e) {
|
||||
throw new RestException(e);
|
||||
}
|
||||
});
|
||||
classLoader.putDynClass(newDynName.replace('/', '.'), bytes, newClazz);
|
||||
RedkaleClassLoader.putReflectionDeclaredConstructors(newClazz, newDynName.replace('/', '.'));
|
||||
for (java.lang.reflect.Type t : retvalTypes) {
|
||||
JsonFactory.root().loadEncoder(t);
|
||||
|
||||
@@ -529,12 +529,9 @@ public abstract class Sncp {
|
||||
}
|
||||
// if (Utility.inNativeImage() || methodBoost == null) { // 加强动态时不能重复加载
|
||||
try {
|
||||
final String newDynClass = newDynName.replace('/', '.');
|
||||
return (Class<T>) classLoader.findClass(newDynClass);
|
||||
} catch (ClassNotFoundException e) {
|
||||
// do nothing
|
||||
return (Class<T>)classLoader.loadClass(newDynName.replace('/', '.'));
|
||||
} catch (Throwable t) {
|
||||
t.printStackTrace();
|
||||
// do nothing
|
||||
}
|
||||
// }
|
||||
// ------------------------------------------------------------------------------
|
||||
@@ -602,8 +599,6 @@ public abstract class Sncp {
|
||||
byte[] bytes = cw.toByteArray();
|
||||
final String newDynClass = newDynName.replace('/', '.');
|
||||
Class<?> newClazz = classLoader.loadClass(newDynClass, bytes);
|
||||
|
||||
classLoader.putDynClass(newDynClass, bytes, newClazz);
|
||||
RedkaleClassLoader.putReflectionPublicClasses(newDynClass);
|
||||
RedkaleClassLoader.putReflectionDeclaredConstructors(newClazz, newDynClass);
|
||||
try {
|
||||
@@ -953,9 +948,7 @@ public abstract class Sncp {
|
||||
newDynName += "_" + (normal ? name : hash(name));
|
||||
}
|
||||
try {
|
||||
final String newDynClass = newDynName.replace('/', '.');
|
||||
Class clz = classLoader.findDynClass(newDynClass);
|
||||
Class newClazz = clz == null ? classLoader.loadClass(newDynClass) : clz;
|
||||
Class newClazz = classLoader.loadClass(newDynName.replace('/', '.'));
|
||||
T service = (T) newClazz.getDeclaredConstructor().newInstance();
|
||||
{
|
||||
Field c = newClazz.getDeclaredField(FIELDPREFIX + "_conf");
|
||||
@@ -1237,7 +1230,6 @@ public abstract class Sncp {
|
||||
byte[] bytes = cw.toByteArray();
|
||||
final String newDynClass = newDynName.replace('/', '.');
|
||||
Class<?> newClazz = classLoader.loadClass(newDynClass, bytes);
|
||||
classLoader.putDynClass(newDynClass, bytes, newClazz);
|
||||
RedkaleClassLoader.putReflectionPublicConstructors(newClazz, newDynClass);
|
||||
RedkaleClassLoader.putReflectionDeclaredConstructors(newClazz, newDynClass);
|
||||
try {
|
||||
|
||||
@@ -359,8 +359,7 @@ public abstract class SncpActionServlet extends SncpServlet {
|
||||
RedkaleClassLoader classLoader = RedkaleClassLoader.getRedkaleClassLoader();
|
||||
Class<?> newClazz = null;
|
||||
try {
|
||||
Class clz = classLoader.findDynClass(newDynName.replace('/', '.'));
|
||||
newClazz = clz == null ? classLoader.loadClass(newDynName.replace('/', '.')) : clz;
|
||||
newClazz = classLoader.loadClass(newDynName.replace('/', '.'));
|
||||
} catch (Throwable ex) {
|
||||
// do nothing
|
||||
}
|
||||
@@ -371,7 +370,8 @@ public abstract class SncpActionServlet extends SncpServlet {
|
||||
TypeToken.getGenericType(method.getGenericReturnType(), serviceClass);
|
||||
|
||||
final Class[] paramClasses = method.getParameterTypes();
|
||||
java.lang.reflect.Type paramComposeBeanType0 = SncpRemoteAction.createParamComposeBeanType(classLoader, serviceImplClass, method, actionid, originalParamTypes, paramClasses);
|
||||
java.lang.reflect.Type paramComposeBeanType0 = SncpRemoteAction.createParamComposeBeanType(
|
||||
classLoader, serviceImplClass, method, actionid, originalParamTypes, paramClasses);
|
||||
if (paramComposeBeanType0 != null && paramComposeBeanType0 == originalParamTypes[0]) {
|
||||
paramComposeBeanType0 = null;
|
||||
}
|
||||
@@ -712,7 +712,6 @@ public abstract class SncpActionServlet extends SncpServlet {
|
||||
|
||||
byte[] bytes = cw.toByteArray();
|
||||
newClazz = classLoader.loadClass(newDynName.replace('/', '.'), bytes);
|
||||
classLoader.putDynClass(newDynName.replace('/', '.'), bytes, newClazz);
|
||||
RedkaleClassLoader.putReflectionDeclaredConstructors(newClazz, newDynName.replace('/', '.'));
|
||||
|
||||
try {
|
||||
|
||||
@@ -56,8 +56,7 @@ public interface SncpAsyncHandler<V, A> extends CompletionHandler<V, A> {
|
||||
+ "__" + handlerClass.getName().replace('.', '/').replace('$', '_');
|
||||
RedkaleClassLoader classLoader = RedkaleClassLoader.getRedkaleClassLoader();
|
||||
try {
|
||||
Class clz = classLoader.findDynClass(newDynName.replace('/', '.'));
|
||||
Class newHandlerClazz = clz == null ? classLoader.loadClass(newDynName.replace('/', '.')) : clz;
|
||||
Class newHandlerClazz = classLoader.loadClass(newDynName.replace('/', '.'));
|
||||
return (Creator<SncpAsyncHandler>) Creator.create(newHandlerClazz);
|
||||
} catch (Throwable ex) {
|
||||
// do nothing
|
||||
@@ -207,7 +206,6 @@ public interface SncpAsyncHandler<V, A> extends CompletionHandler<V, A> {
|
||||
cw.visitEnd();
|
||||
byte[] bytes = cw.toByteArray();
|
||||
Class newClazz = classLoader.loadClass(newDynName.replace('/', '.'), bytes);
|
||||
classLoader.putDynClass(newDynName.replace('/', '.'), bytes, newClazz);
|
||||
return (Creator<SncpAsyncHandler>) Creator.create(newClazz);
|
||||
})
|
||||
.create(factHandler);
|
||||
|
||||
@@ -273,9 +273,7 @@ public final class SncpRemoteAction {
|
||||
final String newDynName = "org/redkaledyn/sncp/servlet/action/_DynSncpActionParamBean_"
|
||||
+ resourceType.getSimpleName() + "_" + method.getName() + "_" + actionid;
|
||||
try {
|
||||
Class clz = classLoader.findDynClass(newDynName.replace('/', '.'));
|
||||
Class<?> newClazz = clz == null ? classLoader.loadClass(newDynName.replace('/', '.')) : clz;
|
||||
return newClazz;
|
||||
return classLoader.loadClass(newDynName.replace('/', '.'));
|
||||
} catch (Throwable ex) {
|
||||
// do nothing
|
||||
}
|
||||
@@ -328,7 +326,6 @@ public final class SncpRemoteAction {
|
||||
|
||||
byte[] bytes = cw.toByteArray();
|
||||
Class newClazz = classLoader.loadClass(newDynName.replace('/', '.'), bytes);
|
||||
classLoader.putDynClass(newDynName.replace('/', '.'), bytes, newClazz);
|
||||
RedkaleClassLoader.putReflectionDeclaredConstructors(newClazz, newDynName.replace('/', '.'));
|
||||
Creator.load(newClazz, 1); // 只一个Object[]参数
|
||||
ProtobufFactory.root().loadDecoder(newClazz);
|
||||
|
||||
@@ -84,8 +84,8 @@ public abstract class EntityFullFunc<T> {
|
||||
final String newDynName = "org/redkaledyn/source/_Dyn" + EntityFullFunc.class.getSimpleName() + "__"
|
||||
+ entityType.getName().replace('.', '_').replace('$', '_');
|
||||
try {
|
||||
Class clz = classLoader.findDynClass(newDynName.replace('/', '.'));
|
||||
return (EntityFullFunc) (clz == null ? classLoader.loadClass(newDynName.replace('/', '.')) : clz)
|
||||
return (EntityFullFunc) classLoader
|
||||
.loadClass(newDynName.replace('/', '.'))
|
||||
.getConstructor(Class.class, Creator.class, Attribute[].class)
|
||||
.newInstance(entityType, creator, attrs);
|
||||
} catch (Throwable ex) {
|
||||
@@ -794,7 +794,6 @@ public abstract class EntityFullFunc<T> {
|
||||
|
||||
byte[] bytes = cw.toByteArray();
|
||||
Class<EntityFullFunc> newClazz = classLoader.loadClass(newDynName.replace('/', '.'), bytes);
|
||||
classLoader.putDynClass(newDynName.replace('/', '.'), bytes, newClazz);
|
||||
RedkaleClassLoader.putReflectionDeclaredConstructors(newClazz, newDynName.replace('/', '.'));
|
||||
try {
|
||||
return newClazz.getConstructor(Class.class, Creator.class, Attribute[].class)
|
||||
|
||||
@@ -66,8 +66,7 @@ public final class DataSqlMapperBuilder {
|
||||
final String newDynName = "org/redkaledyn/source/mapper/_DynDataSqlMapper_"
|
||||
+ mapperType.getName().replace('.', '_').replace('$', '_');
|
||||
try {
|
||||
Class clz = classLoader.findDynClass(newDynName.replace('/', '.'));
|
||||
Class newClazz = clz == null ? classLoader.loadClass(newDynName.replace('/', '.')) : clz;
|
||||
Class newClazz = classLoader.loadClass(newDynName.replace('/', '.'));
|
||||
M mapper = (M) newClazz.getDeclaredConstructor().newInstance();
|
||||
{ // DataSqlSource
|
||||
Field c = newClazz.getDeclaredField("_source");
|
||||
@@ -364,7 +363,6 @@ public final class DataSqlMapperBuilder {
|
||||
|
||||
byte[] bytes = cw.toByteArray();
|
||||
Class<?> newClazz = classLoader.loadClass(newDynName.replace('/', '.'), bytes);
|
||||
classLoader.putDynClass(newDynName.replace('/', '.'), bytes, newClazz);
|
||||
RedkaleClassLoader.putReflectionPublicConstructors(newClazz, newDynName.replace('/', '.'));
|
||||
RedkaleClassLoader.putReflectionDeclaredConstructors(newClazz, newDynName.replace('/', '.'));
|
||||
try {
|
||||
|
||||
@@ -1021,8 +1021,8 @@ public interface Attribute<T, F> {
|
||||
final String newDynName = "org/redkaledyn/attribute/" + pkgname + "_Dyn" + Attribute.class.getSimpleName()
|
||||
+ "__" + clzname + "__" + fieldkey.substring(fieldkey.indexOf('.') + 1);
|
||||
try {
|
||||
Class clz = classLoader.findDynClass(newDynName.replace('/', '.'));
|
||||
Attribute rs = (Attribute) (clz == null ? classLoader.loadClass(newDynName.replace('/', '.')) : clz)
|
||||
Attribute rs = (Attribute) classLoader
|
||||
.loadClass(newDynName.replace('/', '.'))
|
||||
.getDeclaredConstructor()
|
||||
.newInstance();
|
||||
java.lang.reflect.Field _gtype = rs.getClass().getDeclaredField("_gtype");
|
||||
@@ -1234,7 +1234,6 @@ public interface Attribute<T, F> {
|
||||
|
||||
byte[] bytes = cw.toByteArray();
|
||||
Class<Attribute> newClazz = classLoader.loadClass(newDynName.replace('/', '.'), bytes);
|
||||
classLoader.putDynClass(newDynName.replace('/', '.'), bytes, newClazz);
|
||||
RedkaleClassLoader.putReflectionDeclaredConstructors(newClazz, newDynName.replace('/', '.'));
|
||||
try {
|
||||
Attribute rs = newClazz.getDeclaredConstructor().newInstance();
|
||||
|
||||
@@ -688,8 +688,8 @@ public interface Copier<S, D> extends BiFunction<S, D, D> {
|
||||
: ("__" + destClass.getName().replace('.', '_').replace('$', '_')))
|
||||
+ (extendInfo.length() == 0 ? "" : Utility.md5Hex(extendInfo.toString()));
|
||||
try {
|
||||
Class clz = classLoader.findDynClass(newDynName.replace('/', '.'));
|
||||
return (Copier) (clz == null ? classLoader.loadClass(newDynName.replace('/', '.')) : clz)
|
||||
return (Copier) classLoader
|
||||
.loadClass(newDynName.replace('/', '.'))
|
||||
.getDeclaredConstructor()
|
||||
.newInstance();
|
||||
} catch (Throwable ex) {
|
||||
@@ -698,10 +698,7 @@ public interface Copier<S, D> extends BiFunction<S, D, D> {
|
||||
|
||||
// ------------------------------------------------------------------------------
|
||||
ClassWriter cw = new ClassWriter(COMPUTE_FRAMES);
|
||||
FieldVisitor fv;
|
||||
MethodVisitor mv;
|
||||
AnnotationVisitor av0;
|
||||
|
||||
cw.visit(
|
||||
V11,
|
||||
ACC_PUBLIC + ACC_FINAL + ACC_SUPER,
|
||||
@@ -1338,7 +1335,6 @@ public interface Copier<S, D> extends BiFunction<S, D, D> {
|
||||
// ------------------------------------------------------------------------------
|
||||
byte[] bytes = cw.toByteArray();
|
||||
Class<?> newClazz = classLoader.loadClass(newDynName.replace('/', '.'), bytes);
|
||||
classLoader.putDynClass(newDynName.replace('/', '.'), bytes, newClazz);
|
||||
RedkaleClassLoader.putReflectionDeclaredConstructors(newClazz, newDynName.replace('/', '.'));
|
||||
try {
|
||||
return (Copier) newClazz.getDeclaredConstructor().newInstance();
|
||||
|
||||
@@ -296,8 +296,8 @@ public interface Creator<T> {
|
||||
final String newDynName = "org/redkaledyn/creator/_Dyn" + Creator.class.getSimpleName() + "__"
|
||||
+ clazz.getName().replace('.', '_').replace('$', '_') + (paramCount < 0 ? "" : ("_" + paramCount));
|
||||
try {
|
||||
Class clz = classLoader.findDynClass(newDynName.replace('/', '.'));
|
||||
return (Creator) (clz == null ? classLoader.loadClass(newDynName.replace('/', '.')) : clz)
|
||||
return (Creator) classLoader
|
||||
.loadClass(newDynName.replace('/', '.'))
|
||||
.getDeclaredConstructor()
|
||||
.newInstance();
|
||||
} catch (Throwable ex) {
|
||||
@@ -569,7 +569,6 @@ public interface Creator<T> {
|
||||
byte[] bytes = cw.toByteArray();
|
||||
try {
|
||||
Class newClazz = classLoader.loadClass(newDynName.replace('/', '.'), bytes);
|
||||
classLoader.putDynClass(newDynName.replace('/', '.'), bytes, newClazz);
|
||||
RedkaleClassLoader.putReflectionDeclaredConstructors(newClazz, newDynName.replace('/', '.'));
|
||||
return (Creator) newClazz.getDeclaredConstructor().newInstance();
|
||||
} catch (Exception ex) {
|
||||
|
||||
@@ -115,55 +115,34 @@ public abstract class Flows {
|
||||
if (!"executable".equals(System.getProperty("org.graalvm.nativeimage.kind"))) { // not native-image
|
||||
try {
|
||||
//
|
||||
reactorMonoClass0 =
|
||||
Thread.currentThread().getContextClassLoader().loadClass("reactor.core.publisher.Mono");
|
||||
RedkaleClassLoader classLoader = RedkaleClassLoader.getRedkaleClassLoader();
|
||||
reactorMonoClass0 = classLoader.loadClass("reactor.core.publisher.Mono");
|
||||
Class<Function<Object, CompletableFuture>> monoFuncClass = null;
|
||||
try {
|
||||
monoFuncClass = (Class) Thread.currentThread()
|
||||
.getContextClassLoader()
|
||||
.loadClass("org.redkale.util.AnonymousMonoFutureFunction");
|
||||
monoFuncClass = classLoader.loadClass("org.redkale.util.AnonymousMonoFutureFunction");
|
||||
} catch (Throwable t) {
|
||||
// do nothing
|
||||
}
|
||||
if (monoFuncClass == null) {
|
||||
byte[] classBytes = hexToBin(FUNCTION_MONO_FUTRUE_BINARY);
|
||||
monoFuncClass = (Class<Function<Object, CompletableFuture>>)
|
||||
new ClassLoader() {
|
||||
public final Class<?> loadClass(String name, byte[] b) {
|
||||
return defineClass(name, b, 0, b.length);
|
||||
}
|
||||
}.loadClass("org.redkale.util.AnonymousMonoFutureFunction", classBytes);
|
||||
RedkaleClassLoader.getRedkaleClassLoader()
|
||||
.putDynClass(monoFuncClass.getName(), classBytes, monoFuncClass);
|
||||
monoFuncClass = classLoader.loadClass("org.redkale.util.AnonymousMonoFutureFunction", classBytes);
|
||||
}
|
||||
RedkaleClassLoader.putReflectionDeclaredConstructors(monoFuncClass, monoFuncClass.getName());
|
||||
reactorMonoFunction0 = (Function<Object, CompletableFuture>)
|
||||
monoFuncClass.getDeclaredConstructor().newInstance();
|
||||
reactorMonoFunction0 = monoFuncClass.getDeclaredConstructor().newInstance();
|
||||
//
|
||||
reactorFluxClass0 =
|
||||
Thread.currentThread().getContextClassLoader().loadClass("reactor.core.publisher.Flux");
|
||||
reactorFluxClass0 = classLoader.loadClass("reactor.core.publisher.Flux");
|
||||
Class<Function<Object, CompletableFuture>> fluxFuncClass = null;
|
||||
try {
|
||||
fluxFuncClass = (Class) Thread.currentThread()
|
||||
.getContextClassLoader()
|
||||
.loadClass("org.redkale.util.AnonymousFluxFutureFunction");
|
||||
fluxFuncClass = classLoader.loadClass("org.redkale.util.AnonymousFluxFutureFunction");
|
||||
} catch (Throwable t) {
|
||||
// do nothing
|
||||
}
|
||||
if (fluxFuncClass == null) {
|
||||
byte[] classBytes = hexToBin(FUNCTION_FLUX_FUTRUE_BINARY);
|
||||
fluxFuncClass = (Class<Function<Object, CompletableFuture>>)
|
||||
new ClassLoader() {
|
||||
public final Class<?> loadClass(String name, byte[] b) {
|
||||
return defineClass(name, b, 0, b.length);
|
||||
}
|
||||
}.loadClass("org.redkale.util.AnonymousFluxFutureFunction", classBytes);
|
||||
RedkaleClassLoader.getRedkaleClassLoader()
|
||||
.putDynClass(fluxFuncClass.getName(), classBytes, fluxFuncClass);
|
||||
fluxFuncClass = classLoader.loadClass("org.redkale.util.AnonymousFluxFutureFunction", classBytes);
|
||||
}
|
||||
RedkaleClassLoader.putReflectionDeclaredConstructors(fluxFuncClass, fluxFuncClass.getName());
|
||||
reactorFluxFunction0 = (Function<Object, CompletableFuture>)
|
||||
fluxFuncClass.getDeclaredConstructor().newInstance();
|
||||
reactorFluxFunction0 = fluxFuncClass.getDeclaredConstructor().newInstance();
|
||||
} catch (Throwable t) {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
@@ -235,8 +235,8 @@ class Inners {
|
||||
final String newDynName = "org/redkaledyn/creator/_DynArrayFunction__"
|
||||
+ clazz.getName().replace('.', '_').replace('$', '_');
|
||||
try {
|
||||
Class clz = classLoader.findDynClass(newDynName.replace('/', '.'));
|
||||
return (IntFunction) (clz == null ? classLoader.loadClass(newDynName.replace('/', '.')) : clz)
|
||||
return (IntFunction) classLoader
|
||||
.loadClass(newDynName.replace('/', '.'))
|
||||
.getDeclaredConstructor()
|
||||
.newInstance();
|
||||
} catch (Throwable ex) {
|
||||
@@ -284,7 +284,6 @@ class Inners {
|
||||
final byte[] bytes = cw.toByteArray();
|
||||
try {
|
||||
Class<?> resultClazz = classLoader.loadClass(newDynName.replace('/', '.'), bytes);
|
||||
classLoader.putDynClass(newDynName.replace('/', '.'), bytes, resultClazz);
|
||||
RedkaleClassLoader.putReflectionDeclaredConstructors(resultClazz, newDynName.replace('/', '.'));
|
||||
return (IntFunction<T[]>) resultClazz.getDeclaredConstructor().newInstance();
|
||||
} catch (Throwable ex) {
|
||||
|
||||
@@ -99,8 +99,8 @@ public interface Invoker<C, R> {
|
||||
final String newDynName = "org/redkaledyn/invoker/_Dyn" + Invoker.class.getSimpleName() + "_"
|
||||
+ clazz.getName().replace('.', '_').replace('$', '_') + "_" + method.getName() + sbpts;
|
||||
try {
|
||||
Class clz = classLoader.findDynClass(newDynName.replace('/', '.'));
|
||||
return (Invoker<C, T>) (clz == null ? classLoader.loadClass(newDynName.replace('/', '.')) : clz)
|
||||
return (Invoker<C, T>) classLoader
|
||||
.loadClass(newDynName.replace('/', '.'))
|
||||
.getDeclaredConstructor()
|
||||
.newInstance();
|
||||
} catch (Throwable ex) {
|
||||
@@ -204,13 +204,9 @@ public interface Invoker<C, R> {
|
||||
mv.visitEnd();
|
||||
}
|
||||
cw.visitEnd();
|
||||
final byte[] bytes = cw.toByteArray();
|
||||
Class<?> resultClazz = null;
|
||||
byte[] bytes = cw.toByteArray();
|
||||
try {
|
||||
if (resultClazz == null) {
|
||||
resultClazz = classLoader.loadClass(newDynName.replace('/', '.'), bytes);
|
||||
}
|
||||
classLoader.putDynClass(newDynName.replace('/', '.'), bytes, resultClazz);
|
||||
Class<?> resultClazz = classLoader.loadClass(newDynName.replace('/', '.'), bytes);
|
||||
RedkaleClassLoader.putReflectionDeclaredConstructors(resultClazz, newDynName.replace('/', '.'));
|
||||
return (Invoker<C, T>) resultClazz.getDeclaredConstructor().newInstance();
|
||||
} catch (Exception ex) {
|
||||
|
||||
@@ -175,28 +175,6 @@ public class RedkaleClassLoader extends URLClassLoader {
|
||||
}
|
||||
}
|
||||
|
||||
static void putDynClass0(String name, byte[] bs, Class clazz) {
|
||||
Objects.requireNonNull(name);
|
||||
Objects.requireNonNull(bs);
|
||||
Objects.requireNonNull(clazz);
|
||||
allDynClassTypeMap.put(name, clazz);
|
||||
allDynClassBytesMap.put(name, bs);
|
||||
}
|
||||
|
||||
public void putDynClass(String name, byte[] bs, Class clazz) {
|
||||
Objects.requireNonNull(name);
|
||||
Objects.requireNonNull(bs);
|
||||
Objects.requireNonNull(clazz);
|
||||
dynClassTypeMap.put(name, clazz);
|
||||
dynClassBytesMap.put(name, bs);
|
||||
allDynClassTypeMap.put(name, clazz);
|
||||
allDynClassBytesMap.put(name, bs);
|
||||
}
|
||||
|
||||
public Class findDynClass(String name) {
|
||||
return dynClassTypeMap.get(name);
|
||||
}
|
||||
|
||||
public static void forEachDynClass(BiConsumer<String, byte[]> action) {
|
||||
allDynClassBytesMap.forEach(action);
|
||||
}
|
||||
@@ -479,6 +457,10 @@ public class RedkaleClassLoader extends URLClassLoader {
|
||||
}
|
||||
}
|
||||
|
||||
public static byte[] getDynClassBytes(String clazzName) {
|
||||
return allDynClassBytesMap.get(clazzName);
|
||||
}
|
||||
|
||||
// https://www.graalvm.org/reference-manual/native-image/Reflection/#manual-configuration
|
||||
private static Map<String, Object> createMap(String name, Class... cts) {
|
||||
Map<String, Object> map = new LinkedHashMap<>();
|
||||
@@ -495,8 +477,44 @@ public class RedkaleClassLoader extends URLClassLoader {
|
||||
reflectionMap.forEach(action);
|
||||
}
|
||||
|
||||
static void putDynClass0(String name, byte[] bs, Class clazz) {
|
||||
Objects.requireNonNull(name);
|
||||
Objects.requireNonNull(bs);
|
||||
Objects.requireNonNull(clazz);
|
||||
allDynClassTypeMap.put(name, clazz);
|
||||
allDynClassBytesMap.put(name, bs);
|
||||
}
|
||||
|
||||
public void putDynClass2(String name, byte[] bs, Class clazz) {
|
||||
Objects.requireNonNull(name);
|
||||
Objects.requireNonNull(bs);
|
||||
Objects.requireNonNull(clazz);
|
||||
dynClassTypeMap.put(name, clazz);
|
||||
dynClassBytesMap.put(name, bs);
|
||||
allDynClassTypeMap.put(name, clazz);
|
||||
allDynClassBytesMap.put(name, bs);
|
||||
}
|
||||
|
||||
public Class loadClass(String name, byte[] bs) {
|
||||
Class clz = defineClass(name, bs, 0, bs.length);
|
||||
dynClassTypeMap.put(name, clz);
|
||||
dynClassBytesMap.put(name, bs);
|
||||
allDynClassTypeMap.put(name, clz);
|
||||
allDynClassBytesMap.put(name, bs);
|
||||
return clz;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<?> findClass(String name) throws ClassNotFoundException {
|
||||
public Class loadClass(String name) throws ClassNotFoundException {
|
||||
Class clazz = allDynClassTypeMap.get(name);
|
||||
if (clazz != null) {
|
||||
return clazz;
|
||||
}
|
||||
return super.loadClass(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class findClass(String name) throws ClassNotFoundException {
|
||||
byte[] classData = dynClassBytesMap.get(name);
|
||||
if (classData == null) {
|
||||
Class clazz = dynClassTypeMap.get(name);
|
||||
@@ -508,10 +526,6 @@ public class RedkaleClassLoader extends URLClassLoader {
|
||||
return super.defineClass(name, classData, 0, classData.length);
|
||||
}
|
||||
|
||||
public Class loadClass(String name, byte[] b) {
|
||||
return defineClass(name, b, 0, b.length);
|
||||
}
|
||||
|
||||
public void forEachCacheClass(Consumer<String> action) { // getAllURLs返回URL_NONE时需要重载此方法
|
||||
if (this.getParent() instanceof RedkaleClassLoader) {
|
||||
((RedkaleClassLoader) getParent()).forEachCacheClass(action);
|
||||
|
||||
@@ -72,8 +72,8 @@ public interface Reproduce<D, S> extends BiFunction<D, S, D> {
|
||||
+ "__" + destClass.getName().replace('.', '_').replace('$', '_')
|
||||
+ "__" + srcClass.getName().replace('.', '_').replace('$', '_');
|
||||
try {
|
||||
Class clz = classLoader.findDynClass(newDynName.replace('/', '.'));
|
||||
return (Reproduce) (clz == null ? classLoader.loadClass(newDynName.replace('/', '.')) : clz)
|
||||
return (Reproduce) classLoader
|
||||
.loadClass(newDynName.replace('/', '.'))
|
||||
.getDeclaredConstructor()
|
||||
.newInstance();
|
||||
} catch (Throwable ex) {
|
||||
@@ -232,7 +232,6 @@ public interface Reproduce<D, S> extends BiFunction<D, S, D> {
|
||||
// ------------------------------------------------------------------------------
|
||||
byte[] bytes = cw.toByteArray();
|
||||
Class<?> newClazz = classLoader.loadClass(newDynName.replace('/', '.'), bytes);
|
||||
classLoader.putDynClass(newDynName.replace('/', '.'), bytes, newClazz);
|
||||
RedkaleClassLoader.putReflectionDeclaredConstructors(newClazz, newDynName.replace('/', '.'));
|
||||
try {
|
||||
return (Reproduce) newClazz.getDeclaredConstructor().newInstance();
|
||||
|
||||
@@ -716,7 +716,6 @@ public abstract class TypeToken<T> {
|
||||
cw.visitEnd();
|
||||
byte[] bytes = cw.toByteArray();
|
||||
Class<?> newClazz = classLoader.loadClass(newDynName.replace('/', '.'), bytes);
|
||||
classLoader.putDynClass(newDynName.replace('/', '.'), bytes, newClazz);
|
||||
RedkaleClassLoader.putReflectionPublicFields(newDynName.replace('/', '.'));
|
||||
try {
|
||||
return newClazz.getField("field").getGenericType();
|
||||
|
||||
Reference in New Issue
Block a user