2016-02-03 18:48 GMT+03:00 Rainer Jung <[email protected]>: > Hi there, > > ELParser has a field named jj_ls of type LookaheadSuccess which extends > Error. It is created during each instantiation of an ELParser object. > Creating an Error is quite slow, because e.g. it calls > java.lang.Throwable.fillInStack() during init.
Project home for JavaCC + JJTree: https://javacc.java.net/ https://java.net/projects/javacc Looking into source code of their trunk, \src\main\java\org\javacc\parser\ParseGen.java [[[ if (jj2index != 0) { genCodeLine(" @SuppressWarnings(\"serial\")"); genCodeLine(" static private final class LookaheadSuccess extends "+(Options.isLegacyExceptionHandling() ? "java.lang.Error" : "java.lang.RuntimeException")+" { }"); genCodeLine(" " + staticOpt() + "final private LookaheadSuccess jj_ls = new LookaheadSuccess();"); ]]] and \src\main\java\org\javacc\parser\JavaCCGlobals.java [[[ static public String staticOpt() { if (Options.getStatic()) { return "static "; } else { return ""; } } ]]] So 1. There is an option that adds "static" modifier to this field, and actually to all parser methods. It should be good to try that. There is also Options.isLegacyExceptionHandling() in the above code fragment, though it does not matter for this issue. Generally, it will be good to document how these sources are generated. 2. It is known that when using a cached exception instance like that, one must overwrite the fillInStackTrace() method. https://bz.apache.org/bugzilla/show_bug.cgi?id=50460 https://issues.apache.org/jira/browse/XERCESJ-1667 The javacc does not have such feature. (We may propose a patch to them, but who knows when it will be applied). Assuming that the code is regenerated with "static" option on, we can a) patch the generated code by implementing fillInStackTrace() method, b) preload the class. If we patch, we can also do so without regenerating the code. A well known place that preloads classes is org.apache.jasper.security.SecurityClassLoad class, but it preloads classes only when SecurityManager is present. Best regards, Konstantin Kolinko --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
