You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@isis.apache.org by "Andi Huber (JIRA)" <ji...@apache.org> on 2018/12/21 15:52:00 UTC

[jira] [Commented] (ISIS-2054) Reduce memory pressure when reducing calls on getMethod(byName) when looking up annotations.

    [ https://issues.apache.org/jira/browse/ISIS-2054?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16726850#comment-16726850 ] 

Andi Huber commented on ISIS-2054:
----------------------------------

In v2 there is _Reflect (internal API) which has utility functions to recursively traverse class members up the hierarchy. To utilize this one could do ...

 

see commented out code as possible replacement
{code:java}
/**
 * Searches for annotation on provided method, and if not found for any
 * inherited methods up from the superclass.
 *
 * <p>
 * Added to allow bytecode-mangling libraries such as CGLIB to be supported.
 */
public static boolean isAnnotationPresent(final Method method, final Class<? extends Annotation> annotationClass) {
	if (method == null) {
		return false;
	}
	final boolean present = method.isAnnotationPresent(annotationClass);
	if (present) {
		return true;
	}

	final Class<?> methodDeclaringClass = method.getDeclaringClass();

	//TODO [2033] too much heap pollution due to lots of stacktraces produced
	// suggested replacement ...
//        return
//        _Reflect.streamAllMethods(methodDeclaringClass)
//        .filter(m->methodEquals(method, m))
//        .anyMatch(m->m.isAnnotationPresent(annotationClass));

	// search superclasses
	final Class<?> superclass = methodDeclaringClass.getSuperclass();
	if (superclass != null) {
		try {
			final Method parentClassMethod = superclass.getMethod(method.getName(), method.getParameterTypes());
			return isAnnotationPresent(parentClassMethod, annotationClass);
		} catch (final SecurityException | NoSuchMethodException e) {
			// fall through
		}
	}

	// search implemented interfaces
	final Class<?>[] interfaces = methodDeclaringClass.getInterfaces();
	for (final Class<?> iface : interfaces) {
		try {
			final Method ifaceMethod = iface.getMethod(method.getName(), method.getParameterTypes());
			return isAnnotationPresent(ifaceMethod, annotationClass);
		} catch (final SecurityException | NoSuchMethodException e) {
			// fall through
		}
	}
	return false;
}

private static boolean methodEquals(Method m, Method superM) {
	if(!m.getName().equals(superM.getName())) {
		return false;
	}
	if(!m.getReturnType().isAssignableFrom(superM.getReturnType())) {
		return false;
	}
	if(!Arrays.equals(m.getParameterTypes(), superM.getParameterTypes())) {
		return false;
	}
	return true;
	
}

{code}

> Reduce memory pressure when reducing calls on getMethod(byName) when looking up annotations.
> --------------------------------------------------------------------------------------------
>
>                 Key: ISIS-2054
>                 URL: https://issues.apache.org/jira/browse/ISIS-2054
>             Project: Isis
>          Issue Type: Improvement
>    Affects Versions: 1.16.2
>            Reporter: Dan Haywood
>            Priority: Major
>             Fix For: 1.16.3
>
>
> Comment by Andi ...
> think this relates to just noticed we can improve performance of specloader initialization by tweaking ... org.apache.isis.core.metamodel.facets.Annotations such that annotation lookup does no longer call getMethod(byName, ...) 
> this produces a huge amount of stack-trace objects that pollute the heap
> This has already been parallelized, but I think the bottleneck could be memory related :)



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)