Skip to content

Commit

Permalink
Merge pull request #2325 from hongwei1/develop
Browse files Browse the repository at this point in the history
refactor/added the MEMORY_USER comment
  • Loading branch information
simonredfern committed Nov 15, 2023
2 parents f272bf1 + 72c71f7 commit 31819ee
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 7 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 @@ -4191,11 +4191,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 @@ -4207,6 +4210,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 @@ -4233,10 +4237,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,10 +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
ctClass.toClass
// if(ctClass != null) ctClass.detach()
}

private val mirror: ru.Mirror = ru.runtimeMirror(getClass().getClassLoader)
Expand Down

0 comments on commit 31819ee

Please sign in to comment.