Author: markt
Date: Thu Jul 25 15:32:05 2013
New Revision: 1507013
URL: http://svn.apache.org/r1507013
Log:
Merge latest changes from Commons BCEL
Modified:
tomcat/trunk/java/org/apache/tomcat/util/bcel/ (props changed)
tomcat/trunk/java/org/apache/tomcat/util/bcel/classfile/Constant.java
tomcat/trunk/java/org/apache/tomcat/util/bcel/classfile/ConstantUtf8.java
tomcat/trunk/java/org/apache/tomcat/util/bcel/package.html
Propchange: tomcat/trunk/java/org/apache/tomcat/util/bcel/
------------------------------------------------------------------------------
Merged
/commons/proper/bcel/trunk/src/main/java/org/apache/bcel:r1377531-1507004
Modified: tomcat/trunk/java/org/apache/tomcat/util/bcel/classfile/Constant.java
URL:
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/bcel/classfile/Constant.java?rev=1507013&r1=1507012&r2=1507013&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/tomcat/util/bcel/classfile/Constant.java
(original)
+++ tomcat/trunk/java/org/apache/tomcat/util/bcel/classfile/Constant.java Thu
Jul 25 15:32:05 2013
@@ -113,7 +113,7 @@ public abstract class Constant implement
case Constants.CONSTANT_NameAndType:
return new ConstantNameAndType(file);
case Constants.CONSTANT_Utf8:
- return new ConstantUtf8(file);
+ return ConstantUtf8.getInstance(file);
case Constants.CONSTANT_MethodHandle:
return new ConstantMethodHandle(file);
case Constants.CONSTANT_MethodType:
Modified:
tomcat/trunk/java/org/apache/tomcat/util/bcel/classfile/ConstantUtf8.java
URL:
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/bcel/classfile/ConstantUtf8.java?rev=1507013&r1=1507012&r2=1507013&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/tomcat/util/bcel/classfile/ConstantUtf8.java
(original)
+++ tomcat/trunk/java/org/apache/tomcat/util/bcel/classfile/ConstantUtf8.java
Thu Jul 25 15:32:05 2013
@@ -17,7 +17,11 @@
package org.apache.tomcat.util.bcel.classfile;
import java.io.DataInput;
+import java.io.DataInputStream;
import java.io.IOException;
+import java.util.HashMap;
+import java.util.LinkedHashMap;
+import java.util.Map;
import org.apache.tomcat.util.bcel.Constants;
@@ -33,8 +37,42 @@ import org.apache.tomcat.util.bcel.Const
public final class ConstantUtf8 extends Constant {
private static final long serialVersionUID = 8119001312020421976L;
- private String bytes;
+ private final String bytes;
+ private static final int MAX_CACHE_ENTRIES = 20000;
+ private static final int INITIAL_CACHE_CAPACITY =
(int)(MAX_CACHE_ENTRIES/0.75);
+ private static HashMap<String, ConstantUtf8> cache;
+
+ private static synchronized ConstantUtf8 getCachedInstance(String s) {
+ if (s.length() > 200) {
+ return new ConstantUtf8(s);
+ }
+ if (cache == null) {
+ cache = new LinkedHashMap<String,
ConstantUtf8>(INITIAL_CACHE_CAPACITY, 0.75f, true) {
+ private static final long serialVersionUID = 1L;
+
+ @Override
+ protected boolean removeEldestEntry(Map.Entry<String,
ConstantUtf8> eldest) {
+ return size() > MAX_CACHE_ENTRIES;
+ }
+ };
+ }
+ ConstantUtf8 result = cache.get(s);
+ if (result != null) {
+ return result;
+ }
+ result = new ConstantUtf8(s);
+ cache.put(s, result);
+ return result;
+ }
+
+ private static ConstantUtf8 getInstance(String s) {
+ return getCachedInstance(s);
+ }
+
+ static ConstantUtf8 getInstance(DataInputStream file) throws IOException {
+ return getInstance(file.readUTF());
+ }
/**
* Initialize instance from file data.
@@ -49,6 +87,18 @@ public final class ConstantUtf8 extends
/**
+ * @param bytes Data
+ */
+ private ConstantUtf8(String bytes) {
+ super(Constants.CONSTANT_Utf8);
+ if (bytes == null) {
+ throw new IllegalArgumentException("bytes must not be null!");
+ }
+ this.bytes = bytes;
+ }
+
+
+ /**
* @return Data converted to string.
*/
public final String getBytes() {
Modified: tomcat/trunk/java/org/apache/tomcat/util/bcel/package.html
URL:
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/bcel/package.html?rev=1507013&r1=1507012&r2=1507013&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/tomcat/util/bcel/package.html (original)
+++ tomcat/trunk/java/org/apache/tomcat/util/bcel/package.html Thu Jul 25
15:32:05 2013
@@ -24,7 +24,7 @@ $Id$
<body bgcolor="white">
<p>
This package contains basic classes for the
-<a href="http://jakarta.apache.org/bcel/">Byte Code Engineering Library</a>
+<a href="http://commons.apache.org/bcel">Byte Code Engineering Library</a>
and constants defined by the
<a href="http://java.sun.com/docs/books/vmspec/html/VMSpecTOC.doc.html">
JVM specification</a>.
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]