提交 c3a3faac 编写于 作者: C coffeys

7133138: Improve io performance around timezone lookups

Reviewed-by: okutsu
上级 6b77b112
/* /*
* Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2000, 2012, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -26,6 +26,7 @@ ...@@ -26,6 +26,7 @@
package build.tools.javazic; package build.tools.javazic;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
...@@ -162,6 +163,20 @@ class Mappings { ...@@ -162,6 +163,20 @@ class Mappings {
for (String key : toBeRemoved) { for (String key : toBeRemoved) {
aliases.remove(key); aliases.remove(key);
} }
// Eliminate any alias-to-alias mappings. For example, if
// there are A->B and B->C, A->B is changed to A->C.
Map<String, String> newMap = new HashMap<String, String>();
for (String key : aliases.keySet()) {
String realid = aliases.get(key);
String leaf = realid;
while (aliases.get(leaf) != null) {
leaf = aliases.get(leaf);
}
if (!realid.equals(leaf)) {
newMap.put(key, leaf);
}
}
aliases.putAll(newMap);
} }
Map<String,String> getAliases() { Map<String,String> getAliases() {
......
/* /*
* Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2000, 2012, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -79,13 +79,18 @@ public class ZoneInfo extends TimeZone { ...@@ -79,13 +79,18 @@ public class ZoneInfo extends TimeZone {
private static final int TRANSITION_NSHIFT = 12; private static final int TRANSITION_NSHIFT = 12;
// Flag for supporting JDK backward compatible IDs, such as "EST". // Flag for supporting JDK backward compatible IDs, such as "EST".
private static final boolean USE_OLDMAPPING; static final boolean USE_OLDMAPPING;
static { static {
String oldmapping = AccessController.doPrivileged( String oldmapping = AccessController.doPrivileged(
new sun.security.action.GetPropertyAction("sun.timezone.ids.oldmapping", "false")).toLowerCase(Locale.ROOT); new sun.security.action.GetPropertyAction("sun.timezone.ids.oldmapping", "false")).toLowerCase(Locale.ROOT);
USE_OLDMAPPING = (oldmapping.equals("yes") || oldmapping.equals("true")); USE_OLDMAPPING = (oldmapping.equals("yes") || oldmapping.equals("true"));
} }
// IDs having conflicting data between Olson and JDK 1.1
static final String[] conflictingIDs = {
"EST", "MST", "HST"
};
private static final CalendarSystem gcal = CalendarSystem.getGregorianCalendar(); private static final CalendarSystem gcal = CalendarSystem.getGregorianCalendar();
/** /**
...@@ -808,32 +813,41 @@ public class ZoneInfo extends TimeZone { ...@@ -808,32 +813,41 @@ public class ZoneInfo extends TimeZone {
private static SoftReference<Map<String, String>> aliasTable; private static SoftReference<Map<String, String>> aliasTable;
/** static Map<String, String> getCachedAliasTable() {
* Returns a Map from alias time zone IDs to their standard
* time zone IDs.
*
* @return the Map that holds the mappings from alias time zone IDs
* to their standard time zone IDs, or null if
* <code>ZoneInfoMappings</code> file is not available.
*/
public synchronized static Map<String, String> getAliasTable() {
Map<String, String> aliases = null; Map<String, String> aliases = null;
SoftReference<Map<String, String>> cache = aliasTable; SoftReference<Map<String, String>> cache = aliasTable;
if (cache != null) { if (cache != null) {
aliases = cache.get(); aliases = cache.get();
if (aliases != null) {
return aliases;
}
}
aliases = ZoneInfoFile.getZoneAliases();
if (aliases != null) {
aliasTable = new SoftReference<>(aliases);
} }
return aliases; return aliases;
} }
/**
* Returns a Map from alias time zone IDs to their standard
* time zone IDs.
*
* @return the Map that holds the mappings from alias time zone IDs
* to their standard time zone IDs, or null if
* <code>ZoneInfoMappings</code> file is not available.
*/
public synchronized static Map<String, String> getAliasTable() {
Map<String, String> aliases = getCachedAliasTable();
if (aliases == null) {
aliases = ZoneInfoFile.getZoneAliases();
if (aliases != null) {
if (!USE_OLDMAPPING) {
// Remove the conflicting IDs from the alias table.
for (String key : conflictingIDs) {
aliases.remove(key);
}
}
aliasTable = new SoftReference<Map<String, String>>(aliases);
}
}
return aliases;
}
private void readObject(ObjectInputStream stream) private void readObject(ObjectInputStream stream)
throws IOException, ClassNotFoundException { throws IOException, ClassNotFoundException {
stream.defaultReadObject(); stream.defaultReadObject();
......
/* /*
* Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2000, 2012, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -473,6 +473,8 @@ public class ZoneInfoFile { ...@@ -473,6 +473,8 @@ public class ZoneInfoFile {
private static Map<String, ZoneInfo> zoneInfoObjects = null; private static Map<String, ZoneInfo> zoneInfoObjects = null;
private static final ZoneInfo GMT = new ZoneInfo("GMT", 0);
private static final String ziDir = AccessController.doPrivileged( private static final String ziDir = AccessController.doPrivileged(
new PrivilegedAction<String>() { new PrivilegedAction<String>() {
public String run() { public String run() {
...@@ -553,8 +555,15 @@ public class ZoneInfoFile { ...@@ -553,8 +555,15 @@ public class ZoneInfoFile {
* id. * id.
*/ */
public static ZoneInfo getZoneInfo(String id) { public static ZoneInfo getZoneInfo(String id) {
//treat GMT zone as special
if ("GMT".equals(id))
return (ZoneInfo) GMT.clone();
ZoneInfo zi = getFromCache(id); ZoneInfo zi = getFromCache(id);
if (zi == null) { if (zi == null) {
Map<String, String> aliases = ZoneInfo.getCachedAliasTable();
if (aliases != null && aliases.get(id) != null) {
return null;
}
zi = createZoneInfo(id); zi = createZoneInfo(id);
if (zi == null) { if (zi == null) {
return null; return null;
...@@ -1031,30 +1040,26 @@ public class ZoneInfoFile { ...@@ -1031,30 +1040,26 @@ public class ZoneInfoFile {
* @return the buffer, or null if any I/O error occurred. * @return the buffer, or null if any I/O error occurred.
*/ */
private static byte[] readZoneInfoFile(final String fileName) { private static byte[] readZoneInfoFile(final String fileName) {
if (fileName.indexOf("..") >= 0) {
return null;
}
byte[] buffer = null; byte[] buffer = null;
try { try {
buffer = AccessController.doPrivileged(new PrivilegedExceptionAction<byte[]>() { buffer = AccessController.doPrivileged(new PrivilegedExceptionAction<byte[]>() {
public byte[] run() throws IOException { public byte[] run() throws IOException {
File file = new File(ziDir, fileName); File file = new File(ziDir, fileName);
if (!file.exists() || !file.isFile()) {
return null;
}
file = file.getCanonicalFile();
String path = file.getCanonicalPath();
byte[] buf = null; byte[] buf = null;
if (path != null && path.startsWith(ziDir)) { int filesize = (int)file.length();
int filesize = (int)file.length(); if (filesize > 0) {
if (filesize > 0) { FileInputStream fis = new FileInputStream(file);
FileInputStream fis = new FileInputStream(file); buf = new byte[filesize];
buf = new byte[filesize]; try {
try { if (fis.read(buf) != filesize) {
if (fis.read(buf) != filesize) { throw new IOException("read error on " + fileName);
throw new IOException("read error on " + fileName);
}
} finally {
fis.close();
} }
} finally {
fis.close();
} }
} }
return buf; return buf;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册