Skip to content

Commit

Permalink
refactor/added the comments for MEMORY_USER
Browse files Browse the repository at this point in the history
  • Loading branch information
hongwei1 committed Nov 15, 2023
1 parent 819f414 commit 72c71f7
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 9 deletions.
12 changes: 9 additions & 3 deletions obp-api/src/main/scala/code/api/util/APIUtil.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand All @@ -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
Expand All @@ -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
Expand Down
11 changes: 10 additions & 1 deletion obp-api/src/main/scala/code/api/util/DynamicUtil.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 72c71f7

Please sign in to comment.