Fix for #304803 (Remove TypeUtil Integer and Long caches).

git-svn-id: svn+ssh://dev.eclipse.org/svnroot/rt/org.eclipse.jetty/jetty/trunk@1744 7e9141cc-0065-0410-87d8-b60c137991c4
This commit is contained in:
Simone Bordet 2010-05-10 15:12:34 +00:00
parent bcebcb329f
commit c3d31d68b0
11 changed files with 399 additions and 526 deletions

View File

@ -1,9 +1,12 @@
jetty-7.1.1-SNAPSHOT
+ 304803 Remove TypeUtil Integer and Long caches
jetty-7.1.0 5 May 2010
+ 306353 fixed cross context dispatch to root context.
+ 311154 Added deprecated StringBuffer API for backwards compatibility
+ 311554 Protect shutdown thread from Server#doStop
jetty-7.1.0.RC1-SNAPSHOT
jetty-7.1.0.RC1 5 May 2010
+ 286889 Allow System and Server classes to be set on Server instance and when applied to all webapps
+ 291448 SessionManager has isCheckingRemoteSessionIdEncoding
+ 296650 JETTY-1198 reset idle timeout on request body chunks

View File

@ -28,7 +28,6 @@ import org.eclipse.jetty.io.ByteArrayBuffer;
import org.eclipse.jetty.io.EndPoint;
import org.eclipse.jetty.io.EofException;
import org.eclipse.jetty.util.StringUtil;
import org.eclipse.jetty.util.TypeUtil;
import org.eclipse.jetty.util.log.Log;
/**
@ -375,7 +374,7 @@ public class Ajp13Generator extends AbstractGenerator
if (_reason == null)
_reason=HttpGenerator.getReasonBuffer(_status);
if (_reason == null)
_reason = new ByteArrayBuffer(TypeUtil.toString(_status));
_reason = new ByteArrayBuffer(Integer.toString(_status));
addBuffer(_reason);
if (_status == 100 || _status == 204 || _status == 304)

View File

@ -13,8 +13,6 @@
package org.eclipse.jetty.http;
import org.eclipse.jetty.util.TypeUtil;
/**
* <p>
* HttpStatusCode enum class, for status codes based on various HTTP RFCs. (see
@ -947,7 +945,7 @@ public class HttpStatus
}
else
{
return TypeUtil.toString(code);
return Integer.toString(code);
}
}

View File

@ -20,13 +20,11 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.WeakHashMap;
import javax.management.MBeanServer;
import javax.management.ObjectInstance;
import javax.management.ObjectName;
import org.eclipse.jetty.util.MultiMap;
import org.eclipse.jetty.util.TypeUtil;
import org.eclipse.jetty.util.component.AbstractLifeCycle;
import org.eclipse.jetty.util.component.Container;
import org.eclipse.jetty.util.component.Container.Relationship;
@ -265,7 +263,7 @@ public class MBeanContainer extends AbstractLifeCycle implements Container.Liste
String basis=(name!=null&&name.length()>1)?("type="+type+",name="+name):("type="+type);
Integer count = (Integer) _unique.get(basis);
count = TypeUtil.newInteger(count == null ? 0 : (1 + count.intValue()));
count = count == null ? 0 : 1 + count;
_unique.put(basis, count);
//if no explicit domain, create one

View File

@ -20,7 +20,6 @@ import java.io.Writer;
import java.util.ArrayList;
import java.util.Locale;
import java.util.TimeZone;
import javax.servlet.http.Cookie;
import org.eclipse.jetty.http.HttpHeaders;
@ -28,7 +27,6 @@ import org.eclipse.jetty.http.PathMap;
import org.eclipse.jetty.util.DateCache;
import org.eclipse.jetty.util.RolloverFileOutputStream;
import org.eclipse.jetty.util.StringUtil;
import org.eclipse.jetty.util.TypeUtil;
import org.eclipse.jetty.util.Utf8StringBuilder;
import org.eclipse.jetty.util.component.AbstractLifeCycle;
import org.eclipse.jetty.util.log.Log;
@ -380,7 +378,7 @@ public class NCSARequestLog extends AbstractLifeCycle implements RequestLog
if (_logLatency)
{
_writer.write(' ');
_writer.write(TypeUtil.toString(System.currentTimeMillis() - request.getTimeStamp()));
_writer.write(Long.toString(System.currentTimeMillis() - request.getTimeStamp()));
}
_writer.write(StringUtil.__LINE_SEPARATOR);

View File

@ -16,7 +16,6 @@ package org.eclipse.jetty.server.handler;
import java.io.IOException;
import java.io.OutputStream;
import java.net.MalformedURLException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@ -33,7 +32,6 @@ import org.eclipse.jetty.server.HttpConnection;
import org.eclipse.jetty.server.Request;
import org.eclipse.jetty.server.Response;
import org.eclipse.jetty.server.handler.ContextHandler.Context;
import org.eclipse.jetty.util.TypeUtil;
import org.eclipse.jetty.util.URIUtil;
import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.resource.FileResource;
@ -398,7 +396,7 @@ public class ResourceHandler extends AbstractHandler
else
{
if (length>0)
response.setHeader(HttpHeaders.CONTENT_LENGTH,TypeUtil.toString(length));
response.setHeader(HttpHeaders.CONTENT_LENGTH,Long.toString(length));
if (_cacheControl!=null)
response.setHeader(HttpHeaders.CACHE_CONTROL,_cacheControl.toString());

View File

@ -21,7 +21,6 @@ import java.net.URL;
import java.util.Enumeration;
import java.util.List;
import java.util.Map;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
@ -50,7 +49,6 @@ import org.eclipse.jetty.server.nio.NIOConnector;
import org.eclipse.jetty.server.ssl.SslConnector;
import org.eclipse.jetty.util.IO;
import org.eclipse.jetty.util.MultiPartOutputStream;
import org.eclipse.jetty.util.TypeUtil;
import org.eclipse.jetty.util.URIUtil;
import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.resource.FileResource;
@ -903,7 +901,7 @@ public class DefaultServlet extends HttpServlet implements ResourceFactory
if (count<Integer.MAX_VALUE)
response.setContentLength((int)count);
else
response.setHeader(HttpHeaders.CONTENT_LENGTH,TypeUtil.toString(count));
response.setHeader(HttpHeaders.CONTENT_LENGTH,Long.toString(count));
}
writeOptionHeaders(response);

View File

@ -18,7 +18,6 @@ import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
@ -30,7 +29,6 @@ import org.eclipse.jetty.server.HttpConnection;
import org.eclipse.jetty.server.Request;
import org.eclipse.jetty.server.handler.ContextHandler;
import org.eclipse.jetty.server.handler.ErrorHandler;
import org.eclipse.jetty.util.TypeUtil;
import org.eclipse.jetty.util.log.Log;
/** Error Page Error Handler
@ -94,7 +92,7 @@ public class ErrorPageErrorHandler extends ErrorHandler
Integer code=(Integer)request.getAttribute(Dispatcher.ERROR_STATUS_CODE);
if (code!=null)
{
error_page= (String)_errorPages.get(TypeUtil.toString(code.intValue()));
error_page= (String)_errorPages.get(Integer.toString(code));
// if still not found
if ((error_page == null) && (_errorPageList != null))
@ -103,7 +101,7 @@ public class ErrorPageErrorHandler extends ErrorHandler
for (int i = 0; i < _errorPageList.size(); i++)
{
ErrorCodeRange errCode = (ErrorCodeRange) _errorPageList.get(i);
if (errCode.isInRange(code.intValue()))
if (errCode.isInRange(code))
{
error_page = errCode.getUri();
break;
@ -188,7 +186,7 @@ public class ErrorPageErrorHandler extends ErrorHandler
{
if (_errorPages==null)
_errorPages=new HashMap();
_errorPages.put(TypeUtil.toString(code),uri);
_errorPages.put(Integer.toString(code),uri);
}
/* ------------------------------------------------------------ */

View File

@ -24,7 +24,6 @@ import java.net.URI;
import java.net.URISyntaxException;
import java.util.Enumeration;
import java.util.HashSet;
import javax.servlet.Servlet;
import javax.servlet.ServletConfig;
import javax.servlet.ServletContext;
@ -46,7 +45,6 @@ import org.eclipse.jetty.http.HttpURI;
import org.eclipse.jetty.io.Buffer;
import org.eclipse.jetty.io.EofException;
import org.eclipse.jetty.util.IO;
import org.eclipse.jetty.util.TypeUtil;
import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.log.Logger;
import org.eclipse.jetty.util.thread.QueuedThreadPool;
@ -344,7 +342,7 @@ public class ProxyServlet implements Servlet
else if ("content-length".equals(lhdr))
{
contentLength=request.getContentLength();
exchange.setRequestHeader(HttpHeaders.CONTENT_LENGTH,TypeUtil.toString(contentLength));
exchange.setRequestHeader(HttpHeaders.CONTENT_LENGTH,Long.toString(contentLength));
if (contentLength>0)
hasContent=true;
}

View File

@ -25,12 +25,12 @@ import org.eclipse.jetty.util.log.Log;
/* ------------------------------------------------------------ */
/** TYPE Utilities.
/**
* TYPE Utilities.
* Provides various static utiltiy methods for manipulating types and their
* string representations.
*
* @since Jetty 4.1
*
*/
public class TypeUtil
{
@ -38,7 +38,7 @@ public class TypeUtil
public static int LF = '\012';
/* ------------------------------------------------------------ */
private static final HashMap name2Class=new HashMap();
private static final HashMap<String, Class> name2Class=new HashMap<String, Class>();
static
{
name2Class.put("boolean",java.lang.Boolean.TYPE);
@ -86,7 +86,7 @@ public class TypeUtil
}
/* ------------------------------------------------------------ */
private static final HashMap class2Name=new HashMap();
private static final HashMap<Class, String> class2Name=new HashMap<Class, String>();
static
{
class2Name.put(java.lang.Boolean.TYPE,"boolean");
@ -113,7 +113,7 @@ public class TypeUtil
}
/* ------------------------------------------------------------ */
private static final HashMap class2Value=new HashMap();
private static final HashMap<Class, Method> class2Value=new HashMap<Class, Method>();
static
{
try
@ -156,44 +156,6 @@ public class TypeUtil
}
}
/* ------------------------------------------------------------ */
private static Class[] stringArg = { java.lang.String.class };
/* ------------------------------------------------------------ */
private static int intCacheSize = 600;
private static Integer[] integerCache = new Integer[intCacheSize];
private static String[] integerStrCache = new String[intCacheSize];
private static Integer minusOne = new Integer(-1);
private static int longCacheSize = 64;
private static Long[] longCache = new Long[longCacheSize];
private static Long minusOneL = new Long(-1);
public static void setIntCacheSize(int size)
{
if (size > intCacheSize) {
Integer[] intCache = new Integer[size];
System.arraycopy(integerCache,0,intCache,0,intCacheSize);
String [] strCache = new String[size];
System.arraycopy(integerStrCache,0,strCache,0,intCacheSize);
intCacheSize = size;
integerCache = intCache;
integerStrCache = strCache;
}
}
public static void setLongCacheSize(int size)
{
if (size > longCacheSize) {
Long[] lnCache = new Long[size];
System.arraycopy(longCache,0,lnCache,0,longCacheSize);
longCacheSize = size;
longCache = lnCache;
}
}
/* ------------------------------------------------------------ */
/** Class from a canonical name for a type.
* @param name A class or type name.
@ -201,7 +163,7 @@ public class TypeUtil
*/
public static Class fromName(String name)
{
return (Class)name2Class.get(name);
return name2Class.get(name);
}
/* ------------------------------------------------------------ */
@ -211,7 +173,7 @@ public class TypeUtil
*/
public static String toName(Class type)
{
return (String)class2Name.get(type);
return class2Name.get(type);
}
/* ------------------------------------------------------------ */
@ -227,16 +189,16 @@ public class TypeUtil
if (type.equals(java.lang.String.class))
return value;
Method m = (Method)class2Value.get(type);
Method m = class2Value.get(type);
if (m!=null)
return m.invoke(null,new Object[] {value});
return m.invoke(null, value);
if (type.equals(java.lang.Character.TYPE) ||
type.equals(java.lang.Character.class))
return new Character(value.charAt(0));
Constructor c = type.getConstructor(stringArg);
return c.newInstance(new Object[] {value});
Constructor c = type.getConstructor(java.lang.String.class);
return c.newInstance(value);
}
catch(NoSuchMethodException e)
{
@ -270,72 +232,6 @@ public class TypeUtil
return valueOf(fromName(type),value);
}
/* ------------------------------------------------------------ */
/** Convert int to Integer using cache.
*/
public static Integer newInteger(int i)
{
if (i>=0 && i<intCacheSize)
{
if (integerCache[i]==null)
integerCache[i]=new Integer(i);
return integerCache[i];
}
else if (i==-1)
return minusOne;
return new Integer(i);
}
/* ------------------------------------------------------------ */
/** Convert int to Integer using cache.
*/
public static Long newLong(long i)
{
if (i>=0 && i<longCacheSize)
{
if (longCache[(int)i]==null)
longCache[(int)i]=new Long(i);
return longCache[(int)i];
}
else if (i==-1)
return minusOneL;
return new Long(i);
}
/* ------------------------------------------------------------ */
/** Convert int to String using cache.
*/
public static String toString(int i)
{
if (i>=0 && i<intCacheSize)
{
if (integerStrCache[i]==null)
integerStrCache[i]=Integer.toString(i);
return integerStrCache[i];
}
else if (i==-1)
return "-1";
return Integer.toString(i);
}
/* ------------------------------------------------------------ */
/** Convert long to String using cache.
*/
public static String toString(long i)
{
if (i>=0 && i<intCacheSize)
{
if (integerStrCache[(int)i]==null)
integerStrCache[(int)i]=Long.toString(i);
return integerStrCache[(int)i];
}
else if (i==-1)
return "-1";
return Long.toString(i);
}
/* ------------------------------------------------------------ */
/** Parse an int from a substring.
* Negative numbers are not handled.
@ -343,7 +239,8 @@ public class TypeUtil
* @param offset Offset within string
* @param length Length of integer or -1 for remainder of string
* @param base base of the integer
* @exception NumberFormatException
* @return the parsed integer
* @throws NumberFormatException if the string cannot be parsed
*/
public static int parseInt(String s, int offset, int length, int base)
throws NumberFormatException
@ -378,7 +275,8 @@ public class TypeUtil
* @param offset Offset within string
* @param length Length of integer or -1 for remainder of string
* @param base base of the integer
* @exception NumberFormatException
* @return the parsed integer
* @throws NumberFormatException if the array cannot be parsed into an integer
*/
public static int parseInt(byte[] b, int offset, int length, int base)
throws NumberFormatException
@ -419,9 +317,9 @@ public class TypeUtil
public static String toString(byte[] bytes, int base)
{
StringBuilder buf = new StringBuilder();
for (int i=0;i<bytes.length;i++)
for (byte b : bytes)
{
int bi=0xff&bytes[i];
int bi=0xff&b;
int c='0'+(bi/base)%base;
if (c>'9')
c= 'a'+(c-'0'-10);
@ -471,20 +369,7 @@ public class TypeUtil
/* ------------------------------------------------------------ */
public static String toHexString(byte[] b)
{
StringBuilder buf = new StringBuilder();
for (int i=0;i<b.length;i++)
{
int bi=0xff&b[i];
int c='0'+(bi/16)%16;
if (c>'9')
c= 'A'+(c-'0'-10);
buf.append((char)c);
c='0'+bi%16;
if (c>'9')
c= 'a'+(c-'0'-10);
buf.append((char)c);
}
return buf.toString();
return toHexString(b, 0, b.length);
}
/* ------------------------------------------------------------ */

View File

@ -1215,7 +1215,7 @@ public class JSON
}
if (buffer == null)
return TypeUtil.newLong(minus?-1 * number:number);
return minus ? -1 * number : number;
doubleLoop: while (source.hasNext())
{
@ -1395,7 +1395,7 @@ public class JSON
_buffer.append(c);
QuotedStringTokenizer.quote(_buffer,name);
_buffer.append(':');
appendNumber(_buffer,TypeUtil.newLong(value));
appendNumber(_buffer, value);
c = ',';
}
catch (IOException e)