Heads up - Ran into something I haven't seen before

Bernd Eckenfels bernd-2012 at eckenfels.net
Sat Feb 16 01:52:18 UTC 2013


not sure where the original discussion took place (and I am not sure what
the reason for the GC activity is), but this here alerted me a bit:

>>>   at java.util.regex.Pattern.compile(Pattern.java:1055)
>>>   at java.lang.String.replace(String.java:2227)
>>>   at  
>>> jdk.nashorn.internal.codegen.RuntimeCallSite.makeMethod(RuntimeCallSite.java:282)
>>>   at  
>>> jdk.nashorn.internal.codegen.RuntimeCallSite.next(RuntimeCallSite.java:343)

Isn't nashorn supposed to be high performance? I would avoid using
String.replace() as it compiles the pattern matcher each time you call it.

Not sure if this is the actual code (I could not match the line numbers to
some source on the web):

METHODS.get(request.name().replace("_STRICT", "") +

But, if this is supposed to remove a trailing (optional) strict before
concatenation, the following code will use less objects (and using indexOf
instead of lastIndexOf will improve it even more).

		StringBuilder sb = new StringBuilder("test_STRICT");
		int pos = sb.lastIndexOf("_STRICT");
		if (pos > -1)

BTW: what happens if the mothod name contains "_STRICT"?


More information about the hotspot-gc-dev mailing list