Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openanolis
dragonwell8_langtools
提交
e109ae53
D
dragonwell8_langtools
项目概览
openanolis
/
dragonwell8_langtools
通知
0
Star
2
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
D
dragonwell8_langtools
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
e109ae53
编写于
3月 07, 2011
作者:
K
ksrini
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
7021927: javac: regression in performance
Reviewed-by: jjg
上级
80255a83
变更
10
隐藏空白更改
内联
并排
Showing
10 changed file
with
454 addition
and
31 deletion
+454
-31
src/share/classes/com/sun/tools/javac/file/JavacFileManager.java
...re/classes/com/sun/tools/javac/file/JavacFileManager.java
+30
-11
src/share/classes/com/sun/tools/javac/file/ZipFileIndex.java
src/share/classes/com/sun/tools/javac/file/ZipFileIndex.java
+44
-2
src/share/classes/com/sun/tools/javac/util/Options.java
src/share/classes/com/sun/tools/javac/util/Options.java
+16
-0
test/tools/javac/6508981/TestInferBinaryName.java
test/tools/javac/6508981/TestInferBinaryName.java
+2
-3
test/tools/javac/api/6411310/Test.java
test/tools/javac/api/6411310/Test.java
+5
-7
test/tools/javac/api/T6838467.java
test/tools/javac/api/T6838467.java
+3
-5
test/tools/javac/api/T6877206.java
test/tools/javac/api/T6877206.java
+1
-3
test/tools/javac/file/zip/T6836682.java
test/tools/javac/file/zip/T6836682.java
+156
-0
test/tools/javac/file/zip/T6865530.java
test/tools/javac/file/zip/T6865530.java
+66
-0
test/tools/javac/file/zip/Utils.java
test/tools/javac/file/zip/Utils.java
+131
-0
未找到文件。
src/share/classes/com/sun/tools/javac/file/JavacFileManager.java
浏览文件 @
e109ae53
...
@@ -89,7 +89,7 @@ public class JavacFileManager extends BaseFileManager implements StandardJavaFil
...
@@ -89,7 +89,7 @@ public class JavacFileManager extends BaseFileManager implements StandardJavaFil
private
FSInfo
fsInfo
;
private
FSInfo
fsInfo
;
private
boolean
useZipFileIndex
;
private
boolean
contextUseOptimizedZip
;
private
ZipFileIndexCache
zipFileIndexCache
;
private
ZipFileIndexCache
zipFileIndexCache
;
private
final
File
uninited
=
new
File
(
"U N I N I T E D"
);
private
final
File
uninited
=
new
File
(
"U N I N I T E D"
);
...
@@ -164,8 +164,8 @@ public class JavacFileManager extends BaseFileManager implements StandardJavaFil
...
@@ -164,8 +164,8 @@ public class JavacFileManager extends BaseFileManager implements StandardJavaFil
fsInfo
=
FSInfo
.
instance
(
context
);
fsInfo
=
FSInfo
.
instance
(
context
);
useZipFileIndex
=
options
.
isSet
(
"useOptimizedZip"
);
contextUseOptimizedZip
=
options
.
getBoolean
(
"useOptimizedZip"
,
true
);
if
(
useZipFileIndex
)
if
(
contextUseOptimizedZip
)
zipFileIndexCache
=
ZipFileIndexCache
.
getSharedInstance
();
zipFileIndexCache
=
ZipFileIndexCache
.
getSharedInstance
();
mmappedIO
=
options
.
isSet
(
"mmappedIO"
);
mmappedIO
=
options
.
isSet
(
"mmappedIO"
);
...
@@ -471,9 +471,27 @@ public class JavacFileManager extends BaseFileManager implements StandardJavaFil
...
@@ -471,9 +471,27 @@ public class JavacFileManager extends BaseFileManager implements StandardJavaFil
private
static
final
RelativeDirectory
symbolFilePrefix
private
static
final
RelativeDirectory
symbolFilePrefix
=
new
RelativeDirectory
(
"META-INF/sym/rt.jar/"
);
=
new
RelativeDirectory
(
"META-INF/sym/rt.jar/"
);
/*
* This method looks for a ZipFormatException and takes appropriate
* evasive action. If there is a failure in the fast mode then we
* fail over to the platform zip, and allow it to deal with a potentially
* non compliant zip file.
*/
protected
Archive
openArchive
(
File
zipFilename
)
throws
IOException
{
try
{
return
openArchive
(
zipFilename
,
contextUseOptimizedZip
);
}
catch
(
IOException
ioe
)
{
if
(
ioe
instanceof
ZipFileIndex
.
ZipFormatException
)
{
return
openArchive
(
zipFilename
,
false
);
}
else
{
throw
ioe
;
}
}
}
/** Open a new zip file directory, and cache it.
/** Open a new zip file directory, and cache it.
*/
*/
pr
otected
Archive
openArchive
(
File
zipFileName
)
throws
IOException
{
pr
ivate
Archive
openArchive
(
File
zipFileName
,
boolean
useOptimizedZip
)
throws
IOException
{
File
origZipFileName
=
zipFileName
;
File
origZipFileName
=
zipFileName
;
if
(!
ignoreSymbolFile
&&
paths
.
isDefaultBootClassPathRtJar
(
zipFileName
))
{
if
(!
ignoreSymbolFile
&&
paths
.
isDefaultBootClassPathRtJar
(
zipFileName
))
{
File
file
=
zipFileName
.
getParentFile
().
getParentFile
();
// ${java.home}
File
file
=
zipFileName
.
getParentFile
().
getParentFile
();
// ${java.home}
...
@@ -495,7 +513,7 @@ public class JavacFileManager extends BaseFileManager implements StandardJavaFil
...
@@ -495,7 +513,7 @@ public class JavacFileManager extends BaseFileManager implements StandardJavaFil
boolean
usePreindexedCache
=
false
;
boolean
usePreindexedCache
=
false
;
String
preindexCacheLocation
=
null
;
String
preindexCacheLocation
=
null
;
if
(!
use
ZipFileIndex
)
{
if
(!
use
OptimizedZip
)
{
zdir
=
new
ZipFile
(
zipFileName
);
zdir
=
new
ZipFile
(
zipFileName
);
}
else
{
}
else
{
usePreindexedCache
=
options
.
isSet
(
"usezipindex"
);
usePreindexedCache
=
options
.
isSet
(
"usezipindex"
);
...
@@ -524,23 +542,22 @@ public class JavacFileManager extends BaseFileManager implements StandardJavaFil
...
@@ -524,23 +542,22 @@ public class JavacFileManager extends BaseFileManager implements StandardJavaFil
}
}
if
(
origZipFileName
==
zipFileName
)
{
if
(
origZipFileName
==
zipFileName
)
{
if
(!
use
ZipFileIndex
)
{
if
(!
use
OptimizedZip
)
{
archive
=
new
ZipArchive
(
this
,
zdir
);
archive
=
new
ZipArchive
(
this
,
zdir
);
}
else
{
}
else
{
archive
=
new
ZipFileIndexArchive
(
this
,
archive
=
new
ZipFileIndexArchive
(
this
,
zipFileIndexCache
.
getZipFileIndex
(
zipFileName
,
zipFileIndexCache
.
getZipFileIndex
(
zipFileName
,
null
,
null
,
usePreindexedCache
,
usePreindexedCache
,
preindexCacheLocation
,
preindexCacheLocation
,
options
.
isSet
(
"writezipindexfiles"
)));
options
.
isSet
(
"writezipindexfiles"
)));
}
}
}
else
{
}
else
{
if
(!
use
ZipFileIndex
)
{
if
(!
use
OptimizedZip
)
{
archive
=
new
SymbolArchive
(
this
,
origZipFileName
,
zdir
,
symbolFilePrefix
);
archive
=
new
SymbolArchive
(
this
,
origZipFileName
,
zdir
,
symbolFilePrefix
);
}
}
else
{
else
{
archive
=
new
ZipFileIndexArchive
(
this
,
archive
=
new
ZipFileIndexArchive
(
this
,
zipFileIndexCache
.
getZipFileIndex
(
zipFileName
,
zipFileIndexCache
.
getZipFileIndex
(
zipFileName
,
symbolFilePrefix
,
symbolFilePrefix
,
usePreindexedCache
,
usePreindexedCache
,
preindexCacheLocation
,
preindexCacheLocation
,
...
@@ -549,6 +566,8 @@ public class JavacFileManager extends BaseFileManager implements StandardJavaFil
...
@@ -549,6 +566,8 @@ public class JavacFileManager extends BaseFileManager implements StandardJavaFil
}
}
}
catch
(
FileNotFoundException
ex
)
{
}
catch
(
FileNotFoundException
ex
)
{
archive
=
new
MissingArchive
(
zipFileName
);
archive
=
new
MissingArchive
(
zipFileName
);
}
catch
(
ZipFileIndex
.
ZipFormatException
zfe
)
{
throw
zfe
;
}
catch
(
IOException
ex
)
{
}
catch
(
IOException
ex
)
{
if
(
zipFileName
.
exists
())
if
(
zipFileName
.
exists
())
log
.
error
(
"error.reading.file"
,
zipFileName
,
getMessage
(
ex
));
log
.
error
(
"error.reading.file"
,
zipFileName
,
getMessage
(
ex
));
...
...
src/share/classes/com/sun/tools/javac/file/ZipFileIndex.java
浏览文件 @
e109ae53
...
@@ -492,10 +492,32 @@ public class ZipFileIndex {
...
@@ -492,10 +492,32 @@ public class ZipFileIndex {
public
ZipDirectory
(
RandomAccessFile
zipRandomFile
,
long
start
,
long
end
,
ZipFileIndex
index
)
throws
IOException
{
public
ZipDirectory
(
RandomAccessFile
zipRandomFile
,
long
start
,
long
end
,
ZipFileIndex
index
)
throws
IOException
{
this
.
zipRandomFile
=
zipRandomFile
;
this
.
zipRandomFile
=
zipRandomFile
;
this
.
zipFileIndex
=
index
;
this
.
zipFileIndex
=
index
;
hasValidHeader
();
findCENRecord
(
start
,
end
);
findCENRecord
(
start
,
end
);
}
}
/*
* the zip entry signature should be at offset 0, otherwise allow the
* calling logic to take evasive action by throwing ZipFormatException.
*/
private
boolean
hasValidHeader
()
throws
IOException
{
final
long
pos
=
zipRandomFile
.
getFilePointer
();
try
{
if
(
zipRandomFile
.
read
()
==
'P'
)
{
if
(
zipRandomFile
.
read
()
==
'K'
)
{
if
(
zipRandomFile
.
read
()
==
0x03
)
{
if
(
zipRandomFile
.
read
()
==
0x04
)
{
return
true
;
}
}
}
}
}
finally
{
zipRandomFile
.
seek
(
pos
);
}
throw
new
ZipFormatException
(
"invalid zip magic"
);
}
/*
/*
* Reads zip file central directory.
* Reads zip file central directory.
* For more details see readCEN in zip_util.c from the JDK sources.
* For more details see readCEN in zip_util.c from the JDK sources.
...
@@ -529,7 +551,13 @@ public class ZipFileIndex {
...
@@ -529,7 +551,13 @@ public class ZipFileIndex {
zipDir
=
new
byte
[
get4ByteLittleEndian
(
endbuf
,
i
+
12
)
+
2
];
zipDir
=
new
byte
[
get4ByteLittleEndian
(
endbuf
,
i
+
12
)
+
2
];
zipDir
[
0
]
=
endbuf
[
i
+
10
];
zipDir
[
0
]
=
endbuf
[
i
+
10
];
zipDir
[
1
]
=
endbuf
[
i
+
11
];
zipDir
[
1
]
=
endbuf
[
i
+
11
];
zipRandomFile
.
seek
(
start
+
get4ByteLittleEndian
(
endbuf
,
i
+
16
));
int
sz
=
get4ByteLittleEndian
(
endbuf
,
i
+
16
);
// a negative offset or the entries field indicates a
// potential zip64 archive
if
(
sz
<
0
||
get2ByteLittleEndian
(
zipDir
,
0
)
==
0xffff
)
{
throw
new
ZipFormatException
(
"detected a zip64 archive"
);
}
zipRandomFile
.
seek
(
start
+
sz
);
zipRandomFile
.
readFully
(
zipDir
,
2
,
zipDir
.
length
-
2
);
zipRandomFile
.
readFully
(
zipDir
,
2
,
zipDir
.
length
-
2
);
return
;
return
;
}
else
{
}
else
{
...
@@ -1127,4 +1155,18 @@ public class ZipFileIndex {
...
@@ -1127,4 +1155,18 @@ public class ZipFileIndex {
}
}
}
}
/*
* Exception primarily used to implement a failover, used exclusively here.
*/
static
final
class
ZipFormatException
extends
IOException
{
private
static
final
long
serialVersionUID
=
8000196834066748623L
;
protected
ZipFormatException
(
String
message
)
{
super
(
message
);
}
protected
ZipFormatException
(
String
message
,
Throwable
cause
)
{
super
(
message
,
cause
);
}
}
}
}
src/share/classes/com/sun/tools/javac/util/Options.java
浏览文件 @
e109ae53
...
@@ -75,6 +75,22 @@ public class Options {
...
@@ -75,6 +75,22 @@ public class Options {
return
values
.
get
(
name
.
optionName
);
return
values
.
get
(
name
.
optionName
);
}
}
/**
* Get the boolean value for an option, patterned after Boolean.getBoolean,
* essentially will return true, iff the value exists and is set to "true".
*/
public
boolean
getBoolean
(
String
name
)
{
return
getBoolean
(
name
,
false
);
}
/**
* Get the boolean with a default value if the option is not set.
*/
public
boolean
getBoolean
(
String
name
,
boolean
defaultValue
)
{
String
value
=
get
(
name
);
return
(
value
==
null
)
?
defaultValue
:
Boolean
.
parseBoolean
(
value
);
}
/**
/**
* Check if the value for an undocumented option has been set.
* Check if the value for an undocumented option has been set.
*/
*/
...
...
test/tools/javac/6508981/TestInferBinaryName.java
浏览文件 @
e109ae53
...
@@ -139,9 +139,8 @@ public class TestInferBinaryName {
...
@@ -139,9 +139,8 @@ public class TestInferBinaryName {
throws
IOException
{
throws
IOException
{
Context
ctx
=
new
Context
();
Context
ctx
=
new
Context
();
Options
options
=
Options
.
instance
(
ctx
);
Options
options
=
Options
.
instance
(
ctx
);
// uugh, ugly back door, should be cleaned up, someday
options
.
put
(
"useOptimizedZip"
,
if
(
zipFileIndexKind
==
USE_ZIP_FILE_INDEX
)
Boolean
.
toString
(
zipFileIndexKind
==
USE_ZIP_FILE_INDEX
));
options
.
put
(
"useOptimizedZip"
,
"true"
);
if
(
symFileKind
==
IGNORE_SYMBOL_FILE
)
if
(
symFileKind
==
IGNORE_SYMBOL_FILE
)
options
.
put
(
"ignore.symbol.file"
,
"true"
);
options
.
put
(
"ignore.symbol.file"
,
"true"
);
...
...
test/tools/javac/api/6411310/Test.java
浏览文件 @
e109ae53
...
@@ -153,14 +153,12 @@ public class Test {
...
@@ -153,14 +153,12 @@ public class Test {
Context
c
=
new
Context
();
Context
c
=
new
Context
();
Options
options
=
Options
.
instance
(
c
);
Options
options
=
Options
.
instance
(
c
);
if
(
useOptimizedZip
)
{
options
.
put
(
"useOptimizedZip"
,
Boolean
.
toString
(
useOptimizedZip
));
options
.
put
(
"useOptimizedZip"
,
"true"
);
}
if
(!
useSymbolFile
)
{
if
(!
useSymbolFile
)
{
options
.
put
(
"ignore.symbol.file"
,
"true"
);
options
.
put
(
"ignore.symbol.file"
,
"true"
);
}
}
return
new
JavacFileManager
(
c
,
false
,
null
);
return
new
JavacFileManager
(
c
,
false
,
null
);
}
}
File
createDir
(
String
name
,
String
...
entries
)
throws
Exception
{
File
createDir
(
String
name
,
String
...
entries
)
throws
Exception
{
...
...
test/tools/javac/api/T6838467.java
浏览文件 @
e109ae53
...
@@ -178,12 +178,10 @@ public class T6838467 {
...
@@ -178,12 +178,10 @@ public class T6838467 {
return
fm
;
return
fm
;
}
}
JavacFileManager
createFileManager
(
boolean
useOptim
edZipIndex
)
{
JavacFileManager
createFileManager
(
boolean
useOptim
izedZip
)
{
Context
ctx
=
new
Context
();
Context
ctx
=
new
Context
();
if
(
useOptimedZipIndex
)
{
Options
options
=
Options
.
instance
(
ctx
);
Options
options
=
Options
.
instance
(
ctx
);
options
.
put
(
"useOptimizedZip"
,
Boolean
.
toString
(
useOptimizedZip
));
options
.
put
(
"useOptimizedZip"
,
"true"
);
}
return
new
JavacFileManager
(
ctx
,
false
,
null
);
return
new
JavacFileManager
(
ctx
,
false
,
null
);
}
}
...
...
test/tools/javac/api/T6877206.java
浏览文件 @
e109ae53
...
@@ -168,9 +168,7 @@ public class T6877206 {
...
@@ -168,9 +168,7 @@ public class T6877206 {
JavacFileManager
createFileManager
(
boolean
useOptimizedZip
,
boolean
useSymbolFile
)
{
JavacFileManager
createFileManager
(
boolean
useOptimizedZip
,
boolean
useSymbolFile
)
{
Context
ctx
=
new
Context
();
Context
ctx
=
new
Context
();
Options
options
=
Options
.
instance
(
ctx
);
Options
options
=
Options
.
instance
(
ctx
);
if
(
useOptimizedZip
)
{
options
.
put
(
"useOptimizedZip"
,
Boolean
.
toString
(
useOptimizedZip
));
options
.
put
(
"useOptimizedZip"
,
"true"
);
}
if
(!
useSymbolFile
)
{
if
(!
useSymbolFile
)
{
options
.
put
(
"ignore.symbol.file"
,
"true"
);
options
.
put
(
"ignore.symbol.file"
,
"true"
);
}
}
...
...
test/tools/javac/file/zip/T6836682.java
0 → 100644
浏览文件 @
e109ae53
/*
* Copyright (c) 2011, 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.
*/
/*
* @test
* @bug 6836682
* @summary JavacFileManager handles zip64 archives (64K+ entries and large file support)
* @compile -XDignore.symbol.file T6836682.java Utils.java
* @run main T6836682
*/
import
java.io.BufferedOutputStream
;
import
java.io.File
;
import
java.io.FileInputStream
;
import
java.io.FileOutputStream
;
import
java.io.IOException
;
import
java.nio.file.Files
;
import
java.nio.file.Path
;
import
java.util.jar.JarOutputStream
;
import
java.util.zip.ZipEntry
;
public
class
T6836682
{
private
static
final
long
GIGA
=
1024
*
1024
*
1024
;
static
void
createLargeFile
(
File
outFile
,
long
minlength
)
throws
IOException
{
FileOutputStream
fos
=
null
;
BufferedOutputStream
bos
=
null
;
byte
[]
buffer
=
new
byte
[
Short
.
MAX_VALUE
*
2
];
try
{
fos
=
new
FileOutputStream
(
outFile
);
bos
=
new
BufferedOutputStream
(
fos
);
long
count
=
minlength
/
(
Short
.
MAX_VALUE
*
2
)
+
1
;
for
(
long
i
=
0
;
i
<
count
;
i
++)
{
bos
.
write
(
buffer
);
}
}
finally
{
Utils
.
close
(
bos
);
Utils
.
close
(
fos
);
}
if
(
outFile
.
length
()
<
minlength
)
{
throw
new
RuntimeException
(
"could not create large file "
+
outFile
.
getAbsolutePath
());
}
}
static
void
createJarWithLargeFile
(
File
jarFile
,
File
javaFile
,
long
minlength
)
throws
IOException
{
Utils
.
createClassFile
(
javaFile
,
null
,
true
);
File
largeFile
=
new
File
(
"large.data"
);
createLargeFile
(
largeFile
,
minlength
);
String
[]
jarArgs
=
{
"0cvf"
,
jarFile
.
getAbsolutePath
(),
largeFile
.
getName
(),
Utils
.
getClassFileName
(
javaFile
)
};
Utils
.
jarTool
.
run
(
jarArgs
);
// deleted to prevent accidental linkage
new
File
(
Utils
.
getClassFileName
(
javaFile
)).
delete
();
}
static
void
createLargeJar
(
File
jarFile
,
File
javaFile
)
throws
IOException
{
File
classFile
=
new
File
(
Utils
.
getClassFileName
(
javaFile
));
Utils
.
createClassFile
(
javaFile
,
null
,
true
);
JarOutputStream
jos
=
null
;
FileInputStream
fis
=
null
;
try
{
jos
=
new
JarOutputStream
(
new
FileOutputStream
(
jarFile
));
for
(
int
i
=
0
;
i
<
Short
.
MAX_VALUE
*
2
+
10
;
i
++)
{
jos
.
putNextEntry
(
new
ZipEntry
(
"X"
+
i
+
".txt"
));
}
jos
.
putNextEntry
(
new
ZipEntry
(
classFile
.
getName
()));
fis
=
new
FileInputStream
(
classFile
);
Utils
.
copyStream
(
fis
,
jos
);
}
finally
{
Utils
.
close
(
jos
);
Utils
.
close
(
fis
);
}
// deleted to prevent accidental linkage
new
File
(
Utils
.
getClassFileName
(
javaFile
)).
delete
();
}
// a jar with entries exceeding 64k + a class file for the existential test
public
static
void
testLargeJar
(
String
...
args
)
throws
IOException
{
File
largeJar
=
new
File
(
"large.jar"
);
File
javaFile
=
new
File
(
"Foo.java"
);
createLargeJar
(
largeJar
,
javaFile
);
File
testFile
=
new
File
(
"Bar.java"
);
try
{
Utils
.
createJavaFile
(
testFile
,
javaFile
);
if
(!
Utils
.
compile
(
"-doe"
,
"-verbose"
,
"-cp"
,
largeJar
.
getAbsolutePath
(),
testFile
.
getAbsolutePath
()))
{
throw
new
IOException
(
"test failed"
);
}
}
finally
{
Utils
.
deleteFile
(
largeJar
);
}
}
// a jar with an enormous file + a class file for the existential test
public
static
void
testHugeJar
(
String
...
args
)
throws
IOException
{
final
File
largeJar
=
new
File
(
"huge.jar"
);
final
File
javaFile
=
new
File
(
"Foo.java"
);
final
Path
path
=
largeJar
.
getAbsoluteFile
().
getParentFile
().
toPath
();
final
long
available
=
Files
.
getFileStore
(
path
).
getUsableSpace
();
final
long
MAX_VALUE
=
0xFFFF_FFFF
L
;
final
long
absolute
=
MAX_VALUE
+
1L
;
final
long
required
=
(
long
)(
absolute
*
1.1
);
// pad for sundries
System
.
out
.
println
(
"\tavailable: "
+
available
/
GIGA
+
" GB"
);
System
.
out
.
println
(
"\required: "
+
required
/
GIGA
+
" GB"
);
if
(
available
>
required
)
{
createJarWithLargeFile
(
largeJar
,
javaFile
,
absolute
);
File
testFile
=
new
File
(
"Bar.java"
);
Utils
.
createJavaFile
(
testFile
,
javaFile
);
try
{
if
(!
Utils
.
compile
(
"-doe"
,
"-verbose"
,
"-cp"
,
largeJar
.
getAbsolutePath
(),
testFile
.
getAbsolutePath
()))
{
throw
new
IOException
(
"test failed"
);
}
}
finally
{
Utils
.
deleteFile
(
largeJar
);
}
}
else
{
System
.
out
.
println
(
"Warning: test passes vacuously, requirements exceeds available space"
);
}
}
public
static
void
main
(
String
...
args
)
throws
IOException
{
testLargeJar
();
testHugeJar
();
}
}
test/tools/javac/file/zip/T6865530.java
0 → 100644
浏览文件 @
e109ae53
/*
* Copyright (c) 2011, 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.
*/
/*
* @test
* @bug 6865530
* @summary ensure JavacFileManager handles non-standard zipfiles.
* @compile -XDignore.symbol.file T6865530.java
* @run main T6865530
*/
import
java.io.File
;
public
class
T6865530
{
public
static
void
main
(
String
...
args
)
throws
Exception
{
File
badFile
=
new
File
(
"bad.exe"
);
File
testJar
=
new
File
(
"test.jar"
);
File
fooJava
=
new
File
(
"Foo.java"
);
File
barJava
=
new
File
(
"Bar.java"
);
// create a jar by compiling a file, and append the jar to some
// arbitrary data to offset the start of the zip/jar archive
Utils
.
createJavaFile
(
fooJava
);
Utils
.
compile
(
"-doe"
,
"-verbose"
,
fooJava
.
getName
());
String
[]
jarArgs
=
{
"cvf"
,
testJar
.
getAbsolutePath
(),
"Foo.class"
};
Utils
.
jarTool
.
run
(
jarArgs
);
Utils
.
cat
(
badFile
,
fooJava
,
testJar
);
// create test file and use the above file as a classpath
Utils
.
createJavaFile
(
barJava
);
try
{
if
(!
Utils
.
compile
(
"-doe"
,
"-verbose"
,
"-cp"
,
badFile
.
getAbsolutePath
(),
"Bar.java"
))
{
throw
new
RuntimeException
(
"test fails javac did not compile"
);
}
}
finally
{
Utils
.
deleteFile
(
badFile
);
Utils
.
deleteFile
(
testJar
);
}
}
}
test/tools/javac/file/zip/Utils.java
0 → 100644
浏览文件 @
e109ae53
/*
* Copyright (c) 2011, 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.BufferedInputStream
;
import
java.io.BufferedOutputStream
;
import
java.io.Closeable
;
import
java.io.File
;
import
java.io.FileInputStream
;
import
java.io.FileOutputStream
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.io.OutputStream
;
import
java.io.PrintStream
;
public
class
Utils
{
static
final
sun
.
tools
.
jar
.
Main
jarTool
=
new
sun
.
tools
.
jar
.
Main
(
System
.
out
,
System
.
err
,
"jar-tool"
);
static
final
com
.
sun
.
tools
.
javac
.
Main
javac
=
new
com
.
sun
.
tools
.
javac
.
Main
();
private
Utils
(){}
public
static
boolean
compile
(
String
...
args
)
{
return
javac
.
compile
(
args
)
==
0
;
}
public
static
void
createClassFile
(
File
javaFile
,
File
superClass
,
boolean
delete
)
throws
IOException
{
createJavaFile
(
javaFile
,
superClass
);
if
(!
compile
(
javaFile
.
getName
()))
{
throw
new
RuntimeException
(
"compile failed unexpectedly"
);
}
if
(
delete
)
javaFile
.
delete
();
}
public
static
void
createJavaFile
(
File
outFile
)
throws
IOException
{
createJavaFile
(
outFile
,
null
);
}
public
static
void
createJavaFile
(
File
outFile
,
File
superClass
)
throws
IOException
{
PrintStream
ps
=
null
;
String
srcStr
=
"public class "
+
getSimpleName
(
outFile
)
+
" "
;
if
(
superClass
!=
null
)
{
srcStr
=
srcStr
.
concat
(
"extends "
+
getSimpleName
(
superClass
)
+
" "
);
}
srcStr
=
srcStr
.
concat
(
"{}"
);
try
{
FileOutputStream
fos
=
new
FileOutputStream
(
outFile
);
ps
=
new
PrintStream
(
fos
);
ps
.
println
(
srcStr
);
}
finally
{
close
(
ps
);
}
}
static
String
getClassFileName
(
File
javaFile
)
{
return
javaFile
.
getName
().
endsWith
(
".java"
)
?
javaFile
.
getName
().
replace
(
".java"
,
".class"
)
:
null
;
}
static
String
getSimpleName
(
File
inFile
)
{
String
fname
=
inFile
.
getName
();
return
fname
.
substring
(
0
,
fname
.
indexOf
(
"."
));
}
public
static
void
copyStream
(
InputStream
in
,
OutputStream
out
)
throws
IOException
{
byte
[]
buf
=
new
byte
[
8192
];
int
n
=
in
.
read
(
buf
);
while
(
n
>
0
)
{
out
.
write
(
buf
,
0
,
n
);
n
=
in
.
read
(
buf
);
}
}
public
static
void
close
(
Closeable
c
)
{
if
(
c
!=
null
)
{
try
{
c
.
close
();
}
catch
(
IOException
ignore
)
{}
}
}
public
static
void
deleteFile
(
File
f
)
{
if
(!
f
.
delete
())
{
throw
new
RuntimeException
(
"could not delete file: "
+
f
.
getAbsolutePath
());
}
}
public
static
void
cat
(
File
output
,
File
...
files
)
throws
IOException
{
BufferedInputStream
bis
=
null
;
BufferedOutputStream
bos
=
null
;
FileOutputStream
fos
=
null
;
try
{
fos
=
new
FileOutputStream
(
output
);
bos
=
new
BufferedOutputStream
(
fos
);
for
(
File
x
:
files
)
{
FileInputStream
fis
=
new
FileInputStream
(
x
);
bis
=
new
BufferedInputStream
(
fis
);
copyStream
(
bis
,
bos
);
Utils
.
close
(
bis
);
}
}
finally
{
Utils
.
close
(
bis
);
Utils
.
close
(
bos
);
Utils
.
close
(
fos
);
}
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录