From 819f414ded209aa4d0afe60cab2795952dfc617c Mon Sep 17 00:00:00 2001 From: hongwei Date: Wed, 15 Nov 2023 15:36:27 +0100 Subject: [PATCH 1/2] docfix/added the comments for ConnectorBuilderUtil --- .../main/scala/code/bankconnectors/ConnectorBuilderUtil.scala | 2 ++ 1 file changed, 2 insertions(+) diff --git a/obp-api/src/main/scala/code/bankconnectors/ConnectorBuilderUtil.scala b/obp-api/src/main/scala/code/bankconnectors/ConnectorBuilderUtil.scala index 81a99b53c9..04fb22f56d 100644 --- a/obp-api/src/main/scala/code/bankconnectors/ConnectorBuilderUtil.scala +++ b/obp-api/src/main/scala/code/bankconnectors/ConnectorBuilderUtil.scala @@ -27,6 +27,8 @@ object ConnectorBuilderUtil { val m = ct.getDeclaredMethod("getWebUiPropsValue") m.insertBefore("""return ""; """) ct.toClass + // This only used for for connector creation, not during OBP runtime, so it is a bit safe for memory, do not need to clean ct here. + // if(ct != null) ct.detach() } private val mirror: ru.Mirror = ru.runtimeMirror(getClass().getClassLoader) From 72c71f78515b328ceeb1f3b822f5acb1d9e86747 Mon Sep 17 00:00:00 2001 From: hongwei Date: Wed, 15 Nov 2023 16:48:13 +0100 Subject: [PATCH 2/2] refactor/added the comments for MEMORY_USER --- obp-api/src/main/scala/code/api/util/APIUtil.scala | 12 +++++++++--- .../src/main/scala/code/api/util/DynamicUtil.scala | 11 ++++++++++- .../code/bankconnectors/ConnectorBuilderUtil.scala | 10 +++++----- 3 files changed, 24 insertions(+), 9 deletions(-) diff --git a/obp-api/src/main/scala/code/api/util/APIUtil.scala b/obp-api/src/main/scala/code/api/util/APIUtil.scala index 246d9de7de..9a73c6a0b7 100644 --- a/obp-api/src/main/scala/code/api/util/APIUtil.scala +++ b/obp-api/src/main/scala/code/api/util/APIUtil.scala @@ -4330,11 +4330,14 @@ object APIUtil extends MdcLoggable with CustomJsonFormats{ } /** + * NOTE: MEMORY_USER this ctClass will be cached in ClassPool, it may load too many classes into heap. * according class name, method name and method's signature to get all dependent methods */ def getDependentMethods(className: String, methodName:String, signature: String): List[(String, String, String)] = { val methods = ListBuffer[(String, String, String)]() - val method = cp.get(className).getMethod(methodName, signature) + //NOTE: MEMORY_USER this ctClass will be cached in ClassPool, it may load too many classes into heap. + val ctClass = cp.get(className) + val method = ctClass.getMethod(methodName, signature) method.instrument(new ExprEditor() { @throws[CannotCompileException] override def edit(m: MethodCall): Unit = { @@ -4346,6 +4349,7 @@ object APIUtil extends MdcLoggable with CustomJsonFormats{ } /** + * NOTE: MEMORY_USER this ctClass will be cached in ClassPool, it may load too many classes into heap. * get all dependent connector method names for an object * @param endpoint can be OBPEndpoint or other PartialFunction * @return a list of connector method name @@ -4372,10 +4376,12 @@ object APIUtil extends MdcLoggable with CustomJsonFormats{ }.flatten.distinct } - + //NOTE: MEMORY_USER this ctClass will be cached in ClassPool, it may load too many classes into heap. + val ctClass = classPool.get(endpointClassName) + // list of connector method name val connectorMethods: Array[String] = for { - method <- classPool.get(endpointClassName).getDeclaredMethods + method <- ctClass.getDeclaredMethods (clazzName, methodName, _) <- getObpTrace(endpointClassName, method.getName, method.getSignature) if clazzName == connectorTypeName && !methodName.contains("$default$") } yield methodName diff --git a/obp-api/src/main/scala/code/api/util/DynamicUtil.scala b/obp-api/src/main/scala/code/api/util/DynamicUtil.scala index 96a1a6ed6a..6ee1c6aa55 100644 --- a/obp-api/src/main/scala/code/api/util/DynamicUtil.scala +++ b/obp-api/src/main/scala/code/api/util/DynamicUtil.scala @@ -145,11 +145,20 @@ object DynamicUtil extends MdcLoggable{ } } + /** + * NOTE: MEMORY_USER this ctClass will be cached in ClassPool, it may load too many classes into heap. + * @param clazz + * @param predicate + * @return + */ def getDynamicCodeDependentMethods(clazz: Class[_], predicate: String => Boolean = _ => true): List[(String, String, String)] = { val className = clazz.getTypeName val listBuffer = new ListBuffer[(String, String, String)]() + val classPool = getClassPool(clazz.getClassLoader) + //NOTE: MEMORY_USER this ctClass will be cached in ClassPool, it may load too many classes into heap. + val ctClass = classPool.get(className) for { - method <- getClassPool(clazz.getClassLoader).get(className).getDeclaredMethods.toList + method <- ctClass.getDeclaredMethods.toList if predicate(method.getName) ternary @ (typeName, methodName, signature) <- APIUtil.getDependentMethods(className, method.getName, method.getSignature) } yield { diff --git a/obp-api/src/main/scala/code/bankconnectors/ConnectorBuilderUtil.scala b/obp-api/src/main/scala/code/bankconnectors/ConnectorBuilderUtil.scala index 04fb22f56d..bdce90a3fb 100644 --- a/obp-api/src/main/scala/code/bankconnectors/ConnectorBuilderUtil.scala +++ b/obp-api/src/main/scala/code/bankconnectors/ConnectorBuilderUtil.scala @@ -23,12 +23,12 @@ object ConnectorBuilderUtil { { import javassist.ClassPool val pool = ClassPool.getDefault - val ct = pool.getCtClass("code.webuiprops.MappedWebUiPropsProvider$") - val m = ct.getDeclaredMethod("getWebUiPropsValue") + //NOTE: MEMORY_USER this ctClass will be cached in ClassPool, it may load too many classes into heap. + val ctClass = pool.getCtClass("code.webuiprops.MappedWebUiPropsProvider$") + val m = ctClass.getDeclaredMethod("getWebUiPropsValue") m.insertBefore("""return ""; """) - ct.toClass - // This only used for for connector creation, not during OBP runtime, so it is a bit safe for memory, do not need to clean ct here. - // if(ct != null) ct.detach() + ctClass.toClass + // if(ctClass != null) ctClass.detach() } private val mirror: ru.Mirror = ru.runtimeMirror(getClass().getClassLoader)