Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openanolis
dragonwell8_jdk
提交
99561ce7
D
dragonwell8_jdk
项目概览
openanolis
/
dragonwell8_jdk
通知
4
Star
2
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
D
dragonwell8_jdk
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
99561ce7
编写于
5月 20, 2015
作者:
M
mcherkas
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
8066985: Java Webstart downloading packed files can result in Timezone set to UTC
Reviewed-by: ksrini
上级
bc6e7eaf
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
216 addition
and
22 deletion
+216
-22
src/share/classes/com/sun/java/util/jar/pack/PackerImpl.java
src/share/classes/com/sun/java/util/jar/pack/PackerImpl.java
+20
-12
src/share/classes/com/sun/java/util/jar/pack/UnpackerImpl.java
...hare/classes/com/sun/java/util/jar/pack/UnpackerImpl.java
+15
-10
src/share/classes/com/sun/java/util/jar/pack/Utils.java
src/share/classes/com/sun/java/util/jar/pack/Utils.java
+22
-0
test/tools/pack200/DefaultTimeZoneTest.java
test/tools/pack200/DefaultTimeZoneTest.java
+159
-0
未找到文件。
src/share/classes/com/sun/java/util/jar/pack/PackerImpl.java
浏览文件 @
99561ce7
...
...
@@ -79,18 +79,20 @@ public class PackerImpl extends TLGlobals implements Pack200.Packer {
* Takes a JarFile and converts into a pack-stream.
* <p>
* Closes its input but not its output. (Pack200 archives are appendable.)
* @param in a JarFile
*
* @param in a JarFile
* @param out an OutputStream
* @exception IOException if an error is encountered.
*/
public
synchronized
void
pack
(
JarFile
in
,
OutputStream
out
)
throws
IOException
{
assert
(
Utils
.
currentInstance
.
get
()
==
null
);
TimeZone
tz
=
(
props
.
getBoolean
(
Utils
.
PACK_DEFAULT_TIMEZONE
))
?
null
:
TimeZone
.
getDefault
();
assert
(
Utils
.
currentInstance
.
get
()
==
null
);
boolean
needUTC
=
!
props
.
getBoolean
(
Utils
.
PACK_DEFAULT_TIMEZONE
);
try
{
Utils
.
currentInstance
.
set
(
this
);
if
(
tz
!=
null
)
TimeZone
.
setDefault
(
TimeZone
.
getTimeZone
(
"UTC"
));
if
(
needUTC
)
{
Utils
.
changeDefaultTimeZoneToUtc
();
}
if
(
"0"
.
equals
(
props
.
getProperty
(
Pack200
.
Packer
.
EFFORT
)))
{
Utils
.
copyJarFile
(
in
,
out
);
...
...
@@ -99,7 +101,9 @@ public class PackerImpl extends TLGlobals implements Pack200.Packer {
}
}
finally
{
Utils
.
currentInstance
.
set
(
null
);
if
(
tz
!=
null
)
TimeZone
.
setDefault
(
tz
);
if
(
needUTC
)
{
Utils
.
restoreDefaultTimeZone
();
}
in
.
close
();
}
}
...
...
@@ -119,12 +123,13 @@ public class PackerImpl extends TLGlobals implements Pack200.Packer {
* @exception IOException if an error is encountered.
*/
public
synchronized
void
pack
(
JarInputStream
in
,
OutputStream
out
)
throws
IOException
{
assert
(
Utils
.
currentInstance
.
get
()
==
null
);
TimeZone
tz
=
(
props
.
getBoolean
(
Utils
.
PACK_DEFAULT_TIMEZONE
))
?
null
:
TimeZone
.
getDefault
();
assert
(
Utils
.
currentInstance
.
get
()
==
null
);
boolean
needUTC
=
!
props
.
getBoolean
(
Utils
.
PACK_DEFAULT_TIMEZONE
);
try
{
Utils
.
currentInstance
.
set
(
this
);
if
(
tz
!=
null
)
TimeZone
.
setDefault
(
TimeZone
.
getTimeZone
(
"UTC"
));
if
(
needUTC
)
{
Utils
.
changeDefaultTimeZoneToUtc
();
}
if
(
"0"
.
equals
(
props
.
getProperty
(
Pack200
.
Packer
.
EFFORT
)))
{
Utils
.
copyJarFile
(
in
,
out
);
}
else
{
...
...
@@ -132,10 +137,13 @@ public class PackerImpl extends TLGlobals implements Pack200.Packer {
}
}
finally
{
Utils
.
currentInstance
.
set
(
null
);
if
(
tz
!=
null
)
TimeZone
.
setDefault
(
tz
);
if
(
needUTC
)
{
Utils
.
restoreDefaultTimeZone
();
}
in
.
close
();
}
}
/**
* Register a listener for changes to options.
* @param listener An object to be invoked when a property is changed.
...
...
src/share/classes/com/sun/java/util/jar/pack/UnpackerImpl.java
浏览文件 @
99561ce7
...
...
@@ -96,13 +96,15 @@ public class UnpackerImpl extends TLGlobals implements Pack200.Unpacker {
//Driver routines
// The unpack worker...
/**
* Takes a packed-stream InputStream, and writes to a JarOutputStream. Internally
* the entire buffer must be read, it may be more efficient to read the packed-stream
* to a file and pass the File object, in the alternate method described below.
* <p>
* Closes its input but not its output. (The output can accumulate more elements.)
* @param in an InputStream.
*
* @param in an InputStream.
* @param out a JarOutputStream.
* @exception IOException if an error is encountered.
*/
...
...
@@ -113,19 +115,19 @@ public class UnpackerImpl extends TLGlobals implements Pack200.Unpacker {
if
(
out
==
null
)
{
throw
new
NullPointerException
(
"null output"
);
}
assert
(
Utils
.
currentInstance
.
get
()
==
null
);
TimeZone
tz
=
(
props
.
getBoolean
(
Utils
.
PACK_DEFAULT_TIMEZONE
))
?
null
:
TimeZone
.
getDefault
();
assert
(
Utils
.
currentInstance
.
get
()
==
null
);
boolean
needUTC
=
!
props
.
getBoolean
(
Utils
.
PACK_DEFAULT_TIMEZONE
);
try
{
Utils
.
currentInstance
.
set
(
this
);
if
(
tz
!=
null
)
TimeZone
.
setDefault
(
TimeZone
.
getTimeZone
(
"UTC"
));
if
(
needUTC
)
{
Utils
.
changeDefaultTimeZoneToUtc
();
}
final
int
verbose
=
props
.
getInteger
(
Utils
.
DEBUG_VERBOSE
);
BufferedInputStream
in0
=
new
BufferedInputStream
(
in
);
if
(
Utils
.
isJarMagic
(
Utils
.
readMagic
(
in0
)))
{
if
(
verbose
>
0
)
if
(
verbose
>
0
)
{
Utils
.
log
.
info
(
"Copying unpacked JAR file..."
);
}
Utils
.
copyJarFile
(
new
JarInputStream
(
in0
),
out
);
}
else
if
(
props
.
getBoolean
(
Utils
.
DEBUG_DISABLE_NATIVE
))
{
(
new
DoUnpack
()).
run
(
in0
,
out
);
...
...
@@ -144,7 +146,9 @@ public class UnpackerImpl extends TLGlobals implements Pack200.Unpacker {
}
finally
{
_nunp
=
null
;
Utils
.
currentInstance
.
set
(
null
);
if
(
tz
!=
null
)
TimeZone
.
setDefault
(
tz
);
if
(
needUTC
)
{
Utils
.
restoreDefaultTimeZone
();
}
}
}
...
...
@@ -152,7 +156,8 @@ public class UnpackerImpl extends TLGlobals implements Pack200.Unpacker {
* Takes an input File containing the pack file, and generates a JarOutputStream.
* <p>
* Does not close its output. (The output can accumulate more elements.)
* @param in a File.
*
* @param in a File.
* @param out a JarOutputStream.
* @exception IOException if an error is encountered.
*/
...
...
src/share/classes/com/sun/java/util/jar/pack/Utils.java
浏览文件 @
99561ce7
...
...
@@ -34,6 +34,7 @@ import java.io.InputStream;
import
java.io.OutputStream
;
import
java.util.Collections
;
import
java.util.Date
;
import
java.util.TimeZone
;
import
java.util.jar.JarEntry
;
import
java.util.jar.JarFile
;
import
java.util.jar.JarInputStream
;
...
...
@@ -133,6 +134,9 @@ class Utils {
// to the engine code, especially the native code.
static
final
ThreadLocal
<
TLGlobals
>
currentInstance
=
new
ThreadLocal
<>();
private
static
TimeZone
tz
;
private
static
int
workingPackerCount
=
0
;
// convenience method to access the TL globals
static
TLGlobals
getTLGlobals
()
{
return
currentInstance
.
get
();
...
...
@@ -203,6 +207,24 @@ class Utils {
}
}
static
synchronized
void
changeDefaultTimeZoneToUtc
()
{
if
(
workingPackerCount
++
==
0
)
{
// only first thread saves default TZ
tz
=
TimeZone
.
getDefault
();
TimeZone
.
setDefault
(
TimeZone
.
getTimeZone
(
"UTC"
));
}
}
static
synchronized
void
restoreDefaultTimeZone
()
{
if
(--
workingPackerCount
==
0
)
{
// reset timezone when all the packer/unpacker instances have terminated
if
(
tz
!=
null
)
{
TimeZone
.
setDefault
(
tz
);
}
tz
=
null
;
}
}
static
final
Pack200Logger
log
=
new
Pack200Logger
(
"java.util.jar.Pack200"
);
...
...
test/tools/pack200/DefaultTimeZoneTest.java
0 → 100644
浏览文件 @
99561ce7
/*
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
import
java.io.File
;
import
java.io.FileOutputStream
;
import
java.io.IOException
;
import
java.io.OutputStream
;
import
java.util.TimeZone
;
import
java.util.concurrent.CountDownLatch
;
import
java.util.jar.JarFile
;
import
java.util.jar.JarOutputStream
;
import
java.util.jar.Pack200
;
/*
* @test
* @bug 8066985
* @summary multithreading packing/unpacking files can result in Timezone set to UTC
* @compile -XDignore.symbol.file Utils.java DefaultTimeZoneTest.java
* @run main/othervm DefaultTimeZoneTest
* @author mcherkas
*/
public
class
DefaultTimeZoneTest
{
private
static
final
TimeZone
tz
=
TimeZone
.
getTimeZone
(
"Europe/Moscow"
);
private
static
final
int
INIT_THREAD_COUNT
=
Math
.
min
(
4
,
Runtime
.
getRuntime
().
availableProcessors
());
private
static
final
int
MAX_THREAD_COUNT
=
4
*
INIT_THREAD_COUNT
;
private
static
final
long
MINUTE
=
60
*
1000
;
private
static
class
NoOpOutputStream
extends
OutputStream
{
@Override
public
void
write
(
int
b
)
throws
IOException
{
// no op
}
}
static
class
PackAction
implements
Runnable
{
private
Pack200
.
Packer
packer
=
Pack200
.
newPacker
();
private
JarFile
jarFile
;
PackAction
()
throws
IOException
{
jarFile
=
new
JarFile
(
new
File
(
"golden.jar"
));
}
@Override
public
void
run
()
{
try
{
packer
.
pack
(
jarFile
,
new
NoOpOutputStream
());
}
catch
(
IOException
e
)
{
throw
new
RuntimeException
(
e
);
}
}
}
static
class
UnpackAction
implements
Runnable
{
private
Pack200
.
Unpacker
unpacker
=
Pack200
.
newUnpacker
();
private
JarOutputStream
jos
;
private
File
packedJar
=
new
File
(
"golden.pack"
);
UnpackAction
()
throws
IOException
{
jos
=
new
JarOutputStream
(
new
NoOpOutputStream
());
}
@Override
public
void
run
()
{
try
{
unpacker
.
unpack
(
packedJar
,
jos
);
}
catch
(
IOException
e
)
{
throw
new
RuntimeException
(
e
);
}
finally
{
try
{
jos
.
close
();
}
catch
(
IOException
e
)
{
throw
new
RuntimeException
(
e
);
}
}
}
};
public
static
void
test
(
final
Class
<?
extends
Runnable
>
runnableClass
)
throws
InterruptedException
{
for
(
int
i
=
INIT_THREAD_COUNT
;
i
<=
MAX_THREAD_COUNT
;
i
*=
2
)
{
final
CountDownLatch
startLatch
=
new
CountDownLatch
(
i
);
final
CountDownLatch
doneLatch
=
new
CountDownLatch
(
i
);
for
(
int
j
=
0
;
j
<
i
;
j
++)
{
new
Thread
()
{
@Override
public
void
run
()
{
try
{
Runnable
r
=
runnableClass
.
newInstance
();
startLatch
.
countDown
();
startLatch
.
await
();
r
.
run
();
}
catch
(
Exception
e
)
{
throw
new
RuntimeException
(
e
);
}
finally
{
doneLatch
.
countDown
();
}
}
}.
start
();
}
doneLatch
.
await
();
if
(!
TimeZone
.
getDefault
().
equals
(
tz
))
{
throw
new
RuntimeException
(
"FAIL: default time zone was changed"
);
}
}
}
public
static
void
main
(
String
args
[])
throws
IOException
,
InterruptedException
{
TimeZone
.
setDefault
(
tz
);
// make a local copy of our test file
File
srcFile
=
Utils
.
locateJar
(
"golden.jar"
);
final
File
goldenFile
=
new
File
(
"golden.jar"
);
Utils
.
copyFile
(
srcFile
,
goldenFile
);
// created packed file
final
JarFile
goldenJarFile
=
new
JarFile
(
goldenFile
);
final
File
packFile
=
new
File
(
"golden.pack"
);
Utils
.
pack
(
goldenJarFile
,
packFile
);
// before test let's unpack golden pack to warm up
// a native unpacker. That allow us to avoid JDK-8080438
UnpackAction
unpackAction
=
new
UnpackAction
();
unpackAction
.
run
();
long
startTime
=
System
.
currentTimeMillis
();
while
(
System
.
currentTimeMillis
()
-
startTime
<
MINUTE
)
{
// test packer
test
(
PackAction
.
class
);
// test unpacker
test
(
UnpackAction
.
class
);
}
Utils
.
cleanup
();
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录