Merge
This commit is contained in:
commit
0a8da5ffb0
@ -291,3 +291,4 @@ f7c11da0b0481d49cc7a65a453336c108191e821 jdk9-b42
|
||||
12f1e276447bcc81516e85367d53e4f08897049d jdk9-b46
|
||||
b6cca3e6175a69f39e5799b7349ddb0176630291 jdk9-b47
|
||||
0064e246d83f6f9fc245c19b6d05041ecaf4b6d4 jdk9-b48
|
||||
d91ed1951b948210590ce1394bea5515357246ba jdk9-b49
|
||||
|
@ -123,6 +123,7 @@ jdk/src/java.base/share/classes/java/lang/reflect : jdk/src/share/classes/java/l
|
||||
jdk/src/java.base/share/classes/java/math : jdk/src/share/classes/java/math
|
||||
jdk/src/java.base/share/classes/java/net : jdk/src/share/classes/java/net
|
||||
jdk/src/java.base/share/classes/java/nio : jdk/src/share/classes/java/nio
|
||||
jdk/src/java.base/share/classes/java/security/acl : jdk/src/share/classes/java/security/acl
|
||||
jdk/src/java.base/share/classes/java/security/cert : jdk/src/share/classes/java/security/cert
|
||||
jdk/src/java.base/share/classes/java/security/interfaces : jdk/src/share/classes/java/security/interfaces
|
||||
jdk/src/java.base/share/classes/java/security : jdk/src/share/classes/java/security
|
||||
@ -179,6 +180,7 @@ jdk/src/java.base/share/classes/sun/nio/ch : jdk/src/share/classes/sun/nio/ch
|
||||
jdk/src/java.base/share/classes/sun/nio/cs : jdk/src/share/classes/sun/nio/cs
|
||||
jdk/src/java.base/share/classes/sun/nio/fs : jdk/src/share/classes/sun/nio/fs
|
||||
jdk/src/java.base/share/classes/sun/reflect : jdk/src/share/classes/sun/reflect
|
||||
jdk/src/java.base/share/classes/sun/security/acl : jdk/src/share/classes/sun/security/acl
|
||||
jdk/src/java.base/share/classes/sun/security/action : jdk/src/share/classes/sun/security/action
|
||||
jdk/src/java.base/share/classes/sun/security/internal : jdk/src/share/classes/sun/security/internal
|
||||
jdk/src/java.base/share/classes/sun/security/jca : jdk/src/share/classes/sun/security/jca
|
||||
@ -1211,8 +1213,6 @@ jdk/src/java.rmi/share/doc/stub/java/rmi/activation : jdk/src/share/doc/stub/jav
|
||||
jdk/src/java.rmi/unix/bin/java-rmi.cgi.sh : jdk/src/solaris/bin/java-rmi.cgi.sh
|
||||
jdk/src/java.scripting/share/classes/javax/script : jdk/src/share/classes/javax/script
|
||||
jdk/src/java.scripting/share/classes/com/sun/tools/script/shell : jdk/src/share/classes/com/sun/tools/script/shell
|
||||
jdk/src/java.security.acl/share/classes/java/security/acl : jdk/src/share/classes/java/security/acl
|
||||
jdk/src/java.security.acl/share/classes/sun/security/acl : jdk/src/share/classes/sun/security/acl
|
||||
jdk/src/java.security.jgss/macosx/native/libosxkrb5/nativeccache.c : jdk/src/share/native/sun/security/krb5/nativeccache.c
|
||||
jdk/src/java.security.jgss/macosx/native/libosxkrb5/SCDynamicStoreConfig.m : jdk/src/macosx/native/sun/security/krb5/SCDynamicStoreConfig.m
|
||||
jdk/src/java.security.jgss/share/classes/javax/security/auth/kerberos : jdk/src/share/classes/javax/security/auth/kerberos
|
||||
|
@ -291,3 +291,4 @@ e27c725d6c9d155667b35255f442d4ceb8c3c084 jdk9-b40
|
||||
326f2068b4a4c05e2fa27d6acf93eba7b54b090d jdk9-b46
|
||||
ee8447ca632e1d39180b4767c749db101bff7314 jdk9-b47
|
||||
a13c49c5f2899b702652a460ed7aa73123e671e6 jdk9-b48
|
||||
9285d14eb7b6b0815679bae98dd936dbc136218d jdk9-b49
|
||||
|
@ -451,3 +451,4 @@ c363a8b87e477ee45d6d3cb2a36cb365141bc596 jdk9-b38
|
||||
a184ee1d717297bd35b7c3e35393e137921a3ed2 jdk9-b46
|
||||
3b241fb72b8925b75941d612db762a6d5da66d02 jdk9-b47
|
||||
cc775a4a24c7f5d9e624b4205e9fbd48a17331f6 jdk9-b48
|
||||
360cd1fc42f10941a9fd17cc32d5b85a22d12a0b jdk9-b49
|
||||
|
@ -1,5 +1,5 @@
|
||||
#
|
||||
# Copyright (c) 2002, 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
# Copyright (c) 2002, 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
|
||||
@ -132,6 +132,7 @@ SUNWprivate_1.1 {
|
||||
JVM_GetMethodIxSignatureUTF;
|
||||
JVM_GetMethodParameters;
|
||||
JVM_GetMethodTypeAnnotations;
|
||||
JVM_GetNanoTimeAdjustment;
|
||||
JVM_GetPrimitiveArrayElement;
|
||||
JVM_GetProtectionDomain;
|
||||
JVM_GetStackAccessControlContext;
|
||||
|
@ -1,5 +1,5 @@
|
||||
#
|
||||
# Copyright (c) 2002, 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
# Copyright (c) 2002, 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
|
||||
@ -130,6 +130,7 @@ SUNWprivate_1.1 {
|
||||
JVM_GetMethodIxNameUTF;
|
||||
JVM_GetMethodIxSignatureUTF;
|
||||
JVM_GetMethodParameters;
|
||||
JVM_GetNanoTimeAdjustment;
|
||||
JVM_GetPrimitiveArrayElement;
|
||||
JVM_GetProtectionDomain;
|
||||
JVM_GetStackAccessControlContext;
|
||||
|
@ -1,5 +1,5 @@
|
||||
#
|
||||
# Copyright (c) 2002, 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
# Copyright (c) 2002, 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
|
||||
@ -130,6 +130,7 @@
|
||||
_JVM_GetMethodIxSignatureUTF
|
||||
_JVM_GetMethodParameters
|
||||
_JVM_GetMethodTypeAnnotations
|
||||
_JVM_GetNanoTimeAdjustment
|
||||
_JVM_GetPrimitiveArrayElement
|
||||
_JVM_GetProtectionDomain
|
||||
_JVM_GetStackAccessControlContext
|
||||
|
@ -1,5 +1,5 @@
|
||||
#
|
||||
# Copyright (c) 2002, 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
# Copyright (c) 2002, 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
|
||||
@ -130,6 +130,7 @@
|
||||
_JVM_GetMethodIxSignatureUTF
|
||||
_JVM_GetMethodParameters
|
||||
_JVM_GetMethodTypeAnnotations
|
||||
_JVM_GetNanoTimeAdjustment
|
||||
_JVM_GetPrimitiveArrayElement
|
||||
_JVM_GetProtectionDomain
|
||||
_JVM_GetStackAccessControlContext
|
||||
|
@ -1,5 +1,5 @@
|
||||
#
|
||||
# Copyright (c) 2002, 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
# Copyright (c) 2002, 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
|
||||
@ -132,6 +132,7 @@ SUNWprivate_1.1 {
|
||||
JVM_GetMethodIxSignatureUTF;
|
||||
JVM_GetMethodParameters;
|
||||
JVM_GetMethodTypeAnnotations;
|
||||
JVM_GetNanoTimeAdjustment;
|
||||
JVM_GetPrimitiveArrayElement;
|
||||
JVM_GetProtectionDomain;
|
||||
JVM_GetStackAccessControlContext;
|
||||
|
@ -1,5 +1,5 @@
|
||||
#
|
||||
# Copyright (c) 2002, 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
# Copyright (c) 2002, 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
|
||||
@ -132,6 +132,7 @@ SUNWprivate_1.1 {
|
||||
JVM_GetMethodIxSignatureUTF;
|
||||
JVM_GetMethodParameters;
|
||||
JVM_GetMethodTypeAnnotations;
|
||||
JVM_GetNanoTimeAdjustment;
|
||||
JVM_GetPrimitiveArrayElement;
|
||||
JVM_GetProtectionDomain;
|
||||
JVM_GetStackAccessControlContext;
|
||||
|
@ -1,16 +0,0 @@
|
||||
#!/bin/sh
|
||||
|
||||
# If we're cross compiling use that path for nm
|
||||
if [ "$CROSS_COMPILE_ARCH" != "" ]; then
|
||||
NM=$ALT_COMPILER_PATH/nm
|
||||
else
|
||||
NM=nm
|
||||
fi
|
||||
|
||||
$NM --defined-only $* \
|
||||
| awk '{
|
||||
if ($3 ~ /^_ZTV/ || $3 ~ /^gHotSpotVM/) print "\t" $3 ";"
|
||||
if ($3 ~ /^UseSharedSpaces$/) print "\t" $3 ";"
|
||||
if ($3 ~ /^_ZN9Arguments17SharedArchivePathE$/) print "\t" $3 ";"
|
||||
}' \
|
||||
| sort -u
|
@ -1,5 +1,5 @@
|
||||
#
|
||||
# Copyright (c) 2002, 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
# Copyright (c) 2002, 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
|
||||
@ -132,6 +132,7 @@ SUNWprivate_1.1 {
|
||||
JVM_GetMethodIxSignatureUTF;
|
||||
JVM_GetMethodParameters;
|
||||
JVM_GetMethodTypeAnnotations;
|
||||
JVM_GetNanoTimeAdjustment;
|
||||
JVM_GetPrimitiveArrayElement;
|
||||
JVM_GetProtectionDomain;
|
||||
JVM_GetStackAccessControlContext;
|
||||
|
@ -1,5 +1,5 @@
|
||||
#
|
||||
# Copyright (c) 2002, 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
# Copyright (c) 2002, 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
|
||||
@ -132,6 +132,7 @@ SUNWprivate_1.1 {
|
||||
JVM_GetMethodIxSignatureUTF;
|
||||
JVM_GetMethodParameters;
|
||||
JVM_GetMethodTypeAnnotations;
|
||||
JVM_GetNanoTimeAdjustment;
|
||||
JVM_GetPrimitiveArrayElement;
|
||||
JVM_GetProtectionDomain;
|
||||
JVM_GetStackAccessControlContext;
|
||||
|
@ -1,5 +1,5 @@
|
||||
#
|
||||
# Copyright (c) 1999, 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
# Copyright (c) 1999, 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
|
||||
@ -239,8 +239,14 @@ mapfile_reorder : mapfile $(REORDERFILE)
|
||||
rm -f $@
|
||||
cat $^ > $@
|
||||
|
||||
VMDEF_PAT = ^_ZTV
|
||||
VMDEF_PAT := ^gHotSpotVM|$(VMDEF_PAT)
|
||||
VMDEF_PAT := ^UseSharedSpaces$$|$(VMDEF_PAT)
|
||||
VMDEF_PAT := ^_ZN9Arguments17SharedArchivePathE$$|$(VMDEF_PAT)
|
||||
|
||||
vm.def: $(Res_Files) $(Obj_Files)
|
||||
sh $(GAMMADIR)/make/linux/makefiles/build_vm_def.sh *.o > $@
|
||||
$(QUIETLY) $(NM) --defined-only $(Obj_Files) | sort -k3 -u | \
|
||||
awk '$$3 ~ /$(VMDEF_PAT)/ { print "\t" $$3 ";" }' > $@
|
||||
|
||||
mapfile_ext:
|
||||
rm -f $@
|
||||
|
@ -1,5 +1,5 @@
|
||||
#
|
||||
# Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
# Copyright (c) 2000, 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
|
||||
@ -132,6 +132,7 @@ SUNWprivate_1.1 {
|
||||
JVM_GetMethodIxSignatureUTF;
|
||||
JVM_GetMethodParameters;
|
||||
JVM_GetMethodTypeAnnotations;
|
||||
JVM_GetNanoTimeAdjustment;
|
||||
JVM_GetPrimitiveArrayElement;
|
||||
JVM_GetProtectionDomain;
|
||||
JVM_GetStackAccessControlContext;
|
||||
|
@ -1,5 +1,5 @@
|
||||
//
|
||||
// Copyright (c) 1998, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
// Copyright (c) 1998, 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
|
||||
@ -2996,7 +2996,7 @@ enc_class Fast_Unlock(iRegP oop, iRegP box, o7RegP scratch, iRegP scratch2) %{
|
||||
%}
|
||||
|
||||
enc_class enc_String_Equals(o0RegP str1, o1RegP str2, g3RegI cnt, notemp_iRegI result) %{
|
||||
Label Lword_loop, Lpost_word, Lchar, Lchar_loop, Ldone;
|
||||
Label Lchar, Lchar_loop, Ldone;
|
||||
MacroAssembler _masm(&cbuf);
|
||||
|
||||
Register str1_reg = reg_to_register_object($str1$$reg);
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 1997, 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
|
||||
@ -6194,7 +6194,7 @@ void MacroAssembler::string_indexofC8(Register str1, Register str2,
|
||||
ShortBranchVerifier sbv(this);
|
||||
assert(UseSSE42Intrinsics, "SSE4.2 is required");
|
||||
|
||||
// This method uses pcmpestri inxtruction with bound registers
|
||||
// This method uses pcmpestri instruction with bound registers
|
||||
// inputs:
|
||||
// xmm - substring
|
||||
// rax - substring length (elements count)
|
||||
@ -6355,7 +6355,7 @@ void MacroAssembler::string_indexof(Register str1, Register str2,
|
||||
//
|
||||
assert(int_cnt2 == -1 || (0 < int_cnt2 && int_cnt2 < 8), "should be != 0");
|
||||
|
||||
// This method uses pcmpestri inxtruction with bound registers
|
||||
// This method uses pcmpestri instruction with bound registers
|
||||
// inputs:
|
||||
// xmm - substring
|
||||
// rax - substring length (elements count)
|
||||
@ -6644,7 +6644,6 @@ void MacroAssembler::string_compare(Register str1, Register str2,
|
||||
// start from first character again because it has aligned address.
|
||||
int stride2 = 16;
|
||||
int adr_stride = stride << scale;
|
||||
int adr_stride2 = stride2 << scale;
|
||||
|
||||
assert(result == rax && cnt2 == rdx && cnt1 == rcx, "pcmpestri");
|
||||
// rax and rdx are used by pcmpestri as elements counters
|
||||
@ -6743,7 +6742,7 @@ void MacroAssembler::string_compare(Register str1, Register str2,
|
||||
// inputs:
|
||||
// vec1- substring
|
||||
// rax - negative string length (elements count)
|
||||
// mem - scaned string
|
||||
// mem - scanned string
|
||||
// rdx - string length (elements count)
|
||||
// pcmpmask - cmp mode: 11000 (string compare with negated result)
|
||||
// + 00 (unsigned bytes) or + 01 (unsigned shorts)
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 1999, 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 1999, 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright 2012, 2014 SAP AG. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
@ -1115,6 +1115,15 @@ jlong os::javaTimeMillis() {
|
||||
return jlong(time.tv_sec) * 1000 + jlong(time.tv_usec / 1000);
|
||||
}
|
||||
|
||||
void os::javaTimeSystemUTC(jlong &seconds, jlong &nanos) {
|
||||
timeval time;
|
||||
int status = gettimeofday(&time, NULL);
|
||||
assert(status != -1, "aix error at gettimeofday()");
|
||||
seconds = jlong(time.tv_sec);
|
||||
nanos = jlong(time.tv_usec) * 1000;
|
||||
}
|
||||
|
||||
|
||||
// We need to manually declare mread_real_time,
|
||||
// because IBM didn't provide a prototype in time.h.
|
||||
// (they probably only ever tested in C, not C++)
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 1999, 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 1999, 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
|
||||
@ -984,6 +984,14 @@ jlong os::javaTimeMillis() {
|
||||
return jlong(time.tv_sec) * 1000 + jlong(time.tv_usec / 1000);
|
||||
}
|
||||
|
||||
void os::javaTimeSystemUTC(jlong &seconds, jlong &nanos) {
|
||||
timeval time;
|
||||
int status = gettimeofday(&time, NULL);
|
||||
assert(status != -1, "bsd error");
|
||||
seconds = jlong(time.tv_sec);
|
||||
nanos = jlong(time.tv_usec) * 1000;
|
||||
}
|
||||
|
||||
#ifndef __APPLE__
|
||||
#ifndef CLOCK_MONOTONIC
|
||||
#define CLOCK_MONOTONIC (1)
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 1999, 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 1999, 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
|
||||
@ -1322,6 +1322,15 @@ jlong os::javaTimeMillis() {
|
||||
return jlong(time.tv_sec) * 1000 + jlong(time.tv_usec / 1000);
|
||||
}
|
||||
|
||||
void os::javaTimeSystemUTC(jlong &seconds, jlong &nanos) {
|
||||
timeval time;
|
||||
int status = gettimeofday(&time, NULL);
|
||||
assert(status != -1, "linux error");
|
||||
seconds = jlong(time.tv_sec);
|
||||
nanos = jlong(time.tv_usec) * 1000;
|
||||
}
|
||||
|
||||
|
||||
#ifndef CLOCK_MONOTONIC
|
||||
#define CLOCK_MONOTONIC (1)
|
||||
#endif
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 1997, 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
|
||||
@ -1475,6 +1475,16 @@ jlong os::javaTimeMillis() {
|
||||
return jlong(t.tv_sec) * 1000 + jlong(t.tv_usec) / 1000;
|
||||
}
|
||||
|
||||
void os::javaTimeSystemUTC(jlong &seconds, jlong &nanos) {
|
||||
timeval t;
|
||||
if (gettimeofday(&t, NULL) == -1) {
|
||||
fatal(err_msg("os::javaTimeSystemUTC: gettimeofday (%s)", strerror(errno)));
|
||||
}
|
||||
seconds = jlong(t.tv_sec);
|
||||
nanos = jlong(t.tv_usec) * 1000;
|
||||
}
|
||||
|
||||
|
||||
jlong os::javaTimeNanos() {
|
||||
return (jlong)getTimeNanos();
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 1997, 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
|
||||
@ -839,6 +839,12 @@ jlong windows_to_java_time(FILETIME wt) {
|
||||
return (a - offset()) / 10000;
|
||||
}
|
||||
|
||||
// Returns time ticks in (10th of micro seconds)
|
||||
jlong windows_to_time_ticks(FILETIME wt) {
|
||||
jlong a = jlong_from(wt.dwHighDateTime, wt.dwLowDateTime);
|
||||
return (a - offset());
|
||||
}
|
||||
|
||||
FILETIME java_to_windows_time(jlong l) {
|
||||
jlong a = (l * 10000) + offset();
|
||||
FILETIME result;
|
||||
@ -874,6 +880,15 @@ jlong os::javaTimeMillis() {
|
||||
}
|
||||
}
|
||||
|
||||
void os::javaTimeSystemUTC(jlong &seconds, jlong &nanos) {
|
||||
FILETIME wt;
|
||||
GetSystemTimeAsFileTime(&wt);
|
||||
jlong ticks = windows_to_time_ticks(wt); // 10th of micros
|
||||
jlong secs = jlong(ticks / 10000000); // 10000 * 1000
|
||||
seconds = secs;
|
||||
nanos = jlong(ticks - (secs*10000000)) * 100;
|
||||
}
|
||||
|
||||
jlong os::javaTimeNanos() {
|
||||
if (!win32::_has_performance_count) {
|
||||
return javaTimeMillis() * NANOSECS_PER_MILLISEC; // the best we can do.
|
||||
@ -1693,7 +1708,7 @@ void os::win32::print_windows_version(outputStream* st) {
|
||||
}
|
||||
break;
|
||||
|
||||
case 6004:
|
||||
case 10000:
|
||||
if (is_workstation) {
|
||||
st->print("10");
|
||||
} else {
|
||||
|
@ -1950,7 +1950,7 @@ bool ClassVerifier::is_protected_access(instanceKlassHandle this_class,
|
||||
InstanceKlass* target_instance = InstanceKlass::cast(target_class);
|
||||
fieldDescriptor fd;
|
||||
if (is_method) {
|
||||
Method* m = target_instance->uncached_lookup_method(field_name, field_sig, Klass::normal);
|
||||
Method* m = target_instance->uncached_lookup_method(field_name, field_sig, Klass::find_overpass);
|
||||
if (m != NULL && m->is_protected()) {
|
||||
if (!this_class->is_same_class_package(m->method_holder())) {
|
||||
return true;
|
||||
@ -2496,7 +2496,7 @@ void ClassVerifier::verify_invoke_init(
|
||||
Method* m = InstanceKlass::cast(ref_klass)->uncached_lookup_method(
|
||||
vmSymbols::object_initializer_name(),
|
||||
cp->signature_ref_at(bcs->get_index_u2()),
|
||||
Klass::normal);
|
||||
Klass::find_overpass);
|
||||
// Do nothing if method is not found. Let resolution detect the error.
|
||||
if (m != NULL) {
|
||||
instanceKlassHandle mh(THREAD, m->method_holder());
|
||||
|
@ -199,15 +199,10 @@ void CodeCache::initialize_heaps() {
|
||||
}
|
||||
guarantee(NonProfiledCodeHeapSize + ProfiledCodeHeapSize + NonNMethodCodeHeapSize <= ReservedCodeCacheSize, "Size check");
|
||||
|
||||
// Align reserved sizes of CodeHeaps
|
||||
size_t non_method_size = ReservedCodeSpace::allocation_align_size_up(NonNMethodCodeHeapSize);
|
||||
size_t profiled_size = ReservedCodeSpace::allocation_align_size_up(ProfiledCodeHeapSize);
|
||||
size_t non_profiled_size = ReservedCodeSpace::allocation_align_size_up(NonProfiledCodeHeapSize);
|
||||
|
||||
// Compute initial sizes of CodeHeaps
|
||||
size_t init_non_method_size = MIN2(InitialCodeCacheSize, non_method_size);
|
||||
size_t init_profiled_size = MIN2(InitialCodeCacheSize, profiled_size);
|
||||
size_t init_non_profiled_size = MIN2(InitialCodeCacheSize, non_profiled_size);
|
||||
// Align CodeHeaps
|
||||
size_t alignment = heap_alignment();
|
||||
size_t non_method_size = align_size_up(NonNMethodCodeHeapSize, alignment);
|
||||
size_t profiled_size = align_size_down(ProfiledCodeHeapSize, alignment);
|
||||
|
||||
// Reserve one continuous chunk of memory for CodeHeaps and split it into
|
||||
// parts for the individual heaps. The memory layout looks like this:
|
||||
@ -216,18 +211,27 @@ void CodeCache::initialize_heaps() {
|
||||
// Profiled nmethods
|
||||
// Non-nmethods
|
||||
// ---------- low ------------
|
||||
ReservedCodeSpace rs = reserve_heap_memory(non_profiled_size + profiled_size + non_method_size);
|
||||
ReservedCodeSpace rs = reserve_heap_memory(ReservedCodeCacheSize);
|
||||
ReservedSpace non_method_space = rs.first_part(non_method_size);
|
||||
ReservedSpace rest = rs.last_part(non_method_size);
|
||||
ReservedSpace profiled_space = rest.first_part(profiled_size);
|
||||
ReservedSpace non_profiled_space = rest.last_part(profiled_size);
|
||||
|
||||
// Non-nmethods (stubs, adapters, ...)
|
||||
add_heap(non_method_space, "CodeHeap 'non-nmethods'", init_non_method_size, CodeBlobType::NonNMethod);
|
||||
add_heap(non_method_space, "CodeHeap 'non-nmethods'", CodeBlobType::NonNMethod);
|
||||
// Tier 2 and tier 3 (profiled) methods
|
||||
add_heap(profiled_space, "CodeHeap 'profiled nmethods'", init_profiled_size, CodeBlobType::MethodProfiled);
|
||||
add_heap(profiled_space, "CodeHeap 'profiled nmethods'", CodeBlobType::MethodProfiled);
|
||||
// Tier 1 and tier 4 (non-profiled) methods and native methods
|
||||
add_heap(non_profiled_space, "CodeHeap 'non-profiled nmethods'", init_non_profiled_size, CodeBlobType::MethodNonProfiled);
|
||||
add_heap(non_profiled_space, "CodeHeap 'non-profiled nmethods'", CodeBlobType::MethodNonProfiled);
|
||||
}
|
||||
|
||||
size_t CodeCache::heap_alignment() {
|
||||
// If large page support is enabled, align code heaps according to large
|
||||
// page size to make sure that code cache is covered by large pages.
|
||||
const size_t page_size = os::can_execute_large_page_memory() ?
|
||||
os::page_size_for_region_unaligned(ReservedCodeCacheSize, 8) :
|
||||
os::vm_page_size();
|
||||
return MAX2(page_size, (size_t) os::vm_allocation_granularity());
|
||||
}
|
||||
|
||||
ReservedCodeSpace CodeCache::reserve_heap_memory(size_t size) {
|
||||
@ -284,7 +288,7 @@ const char* CodeCache::get_code_heap_flag_name(int code_blob_type) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void CodeCache::add_heap(ReservedSpace rs, const char* name, size_t size_initial, int code_blob_type) {
|
||||
void CodeCache::add_heap(ReservedSpace rs, const char* name, int code_blob_type) {
|
||||
// Check if heap is needed
|
||||
if (!heap_available(code_blob_type)) {
|
||||
return;
|
||||
@ -295,8 +299,8 @@ void CodeCache::add_heap(ReservedSpace rs, const char* name, size_t size_initial
|
||||
_heaps->append(heap);
|
||||
|
||||
// Reserve Space
|
||||
size_t size_initial = MIN2(InitialCodeCacheSize, rs.size());
|
||||
size_initial = round_to(size_initial, os::vm_page_size());
|
||||
|
||||
if (!heap->reserve(rs, size_initial, CodeCacheSegmentSize)) {
|
||||
vm_exit_during_initialization("Could not reserve enough space for code cache");
|
||||
}
|
||||
@ -840,7 +844,7 @@ void CodeCache::initialize() {
|
||||
} else {
|
||||
// Use a single code heap
|
||||
ReservedCodeSpace rs = reserve_heap_memory(ReservedCodeCacheSize);
|
||||
add_heap(rs, "CodeCache", InitialCodeCacheSize, CodeBlobType::All);
|
||||
add_heap(rs, "CodeCache", CodeBlobType::All);
|
||||
}
|
||||
|
||||
// Initialize ICache flush mechanism
|
||||
|
@ -98,12 +98,13 @@ class CodeCache : AllStatic {
|
||||
// CodeHeap management
|
||||
static void initialize_heaps(); // Initializes the CodeHeaps
|
||||
// Creates a new heap with the given name and size, containing CodeBlobs of the given type
|
||||
static void add_heap(ReservedSpace rs, const char* name, size_t size_initial, int code_blob_type);
|
||||
static void add_heap(ReservedSpace rs, const char* name, int code_blob_type);
|
||||
static CodeHeap* get_code_heap(const CodeBlob* cb); // Returns the CodeHeap for the given CodeBlob
|
||||
static CodeHeap* get_code_heap(int code_blob_type); // Returns the CodeHeap for the given CodeBlobType
|
||||
// Returns the name of the VM option to set the size of the corresponding CodeHeap
|
||||
static const char* get_code_heap_flag_name(int code_blob_type);
|
||||
static bool heap_available(int code_blob_type); // Returns true if an own CodeHeap for the given CodeBlobType is available
|
||||
static size_t heap_alignment(); // Returns the alignment of the CodeHeaps in bytes
|
||||
static ReservedCodeSpace reserve_heap_memory(size_t size); // Reserves one continuous chunk of memory for the CodeHeaps
|
||||
|
||||
// Iteration
|
||||
|
@ -553,7 +553,8 @@ static MethodMatcher::Mode check_mode(char name[], const char*& error_msg) {
|
||||
int match = MethodMatcher::Exact;
|
||||
while (name[0] == '*') {
|
||||
match |= MethodMatcher::Suffix;
|
||||
strcpy(name, name + 1);
|
||||
// Copy remaining string plus NUL to the beginning
|
||||
memmove(name, name + 1, strlen(name + 1) + 1);
|
||||
}
|
||||
|
||||
if (strcmp(name, "*") == 0) return MethodMatcher::Any;
|
||||
@ -689,6 +690,13 @@ static MethodMatcher* scan_flag_and_value(const char* type, const char* line, in
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int skip_whitespace(char* line) {
|
||||
// Skip any leading spaces
|
||||
int whitespace_read = 0;
|
||||
sscanf(line, "%*[ \t]%n", &whitespace_read);
|
||||
return whitespace_read;
|
||||
}
|
||||
|
||||
void CompilerOracle::parse_from_line(char* line) {
|
||||
if (line[0] == '\0') return;
|
||||
if (line[0] == '#') return;
|
||||
@ -755,15 +763,9 @@ void CompilerOracle::parse_from_line(char* line) {
|
||||
|
||||
line += bytes_read;
|
||||
|
||||
// Skip any leading spaces before signature
|
||||
int whitespace_read = 0;
|
||||
sscanf(line, "%*[ \t]%n", &whitespace_read);
|
||||
if (whitespace_read > 0) {
|
||||
line += whitespace_read;
|
||||
}
|
||||
|
||||
// there might be a signature following the method.
|
||||
// signatures always begin with ( so match that by hand
|
||||
line += skip_whitespace(line);
|
||||
if (1 == sscanf(line, "(%254[[);/" RANGEBASE "]%n", sig + 1, &bytes_read)) {
|
||||
sig[0] = '(';
|
||||
line += bytes_read;
|
||||
@ -786,7 +788,9 @@ void CompilerOracle::parse_from_line(char* line) {
|
||||
//
|
||||
// For future extensions: extend scan_flag_and_value()
|
||||
char option[256]; // stores flag for Type (1) and type of Type (2)
|
||||
while (sscanf(line, "%*[ \t]%255[a-zA-Z0-9]%n", option, &bytes_read) == 1) {
|
||||
|
||||
line += skip_whitespace(line);
|
||||
while (sscanf(line, "%255[a-zA-Z0-9]%n", option, &bytes_read) == 1) {
|
||||
if (match != NULL && !_quiet) {
|
||||
// Print out the last match added
|
||||
ttyLocker ttyl;
|
||||
@ -816,6 +820,7 @@ void CompilerOracle::parse_from_line(char* line) {
|
||||
// Type (1) option
|
||||
match = add_option_string(c_name, c_match, m_name, m_match, signature, option, true);
|
||||
}
|
||||
line += skip_whitespace(line);
|
||||
} // while(
|
||||
} else {
|
||||
match = add_predicate(command, c_name, c_match, m_name, m_match, signature);
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 1997, 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
|
||||
@ -289,11 +289,11 @@ void LinkResolver::lookup_method_in_klasses(methodHandle& result, KlassHandle kl
|
||||
// returns first instance method
|
||||
// Looks up method in classes, then looks up local default methods
|
||||
void LinkResolver::lookup_instance_method_in_klasses(methodHandle& result, KlassHandle klass, Symbol* name, Symbol* signature, TRAPS) {
|
||||
Method* result_oop = klass->uncached_lookup_method(name, signature, Klass::normal);
|
||||
Method* result_oop = klass->uncached_lookup_method(name, signature, Klass::find_overpass);
|
||||
result = methodHandle(THREAD, result_oop);
|
||||
while (!result.is_null() && result->is_static() && result->method_holder()->super() != NULL) {
|
||||
KlassHandle super_klass = KlassHandle(THREAD, result->method_holder()->super());
|
||||
result = methodHandle(THREAD, super_klass->uncached_lookup_method(name, signature, Klass::normal));
|
||||
result = methodHandle(THREAD, super_klass->uncached_lookup_method(name, signature, Klass::find_overpass));
|
||||
}
|
||||
|
||||
if (klass->oop_is_array()) {
|
||||
@ -320,7 +320,8 @@ int LinkResolver::vtable_index_of_interface_method(KlassHandle klass,
|
||||
// First check in default method array
|
||||
if (!resolved_method->is_abstract() &&
|
||||
(InstanceKlass::cast(klass())->default_methods() != NULL)) {
|
||||
int index = InstanceKlass::find_method_index(InstanceKlass::cast(klass())->default_methods(), name, signature, false, false);
|
||||
int index = InstanceKlass::find_method_index(InstanceKlass::cast(klass())->default_methods(),
|
||||
name, signature, Klass::find_overpass, Klass::find_static);
|
||||
if (index >= 0 ) {
|
||||
vtable_index = InstanceKlass::cast(klass())->default_vtable_indices()->at(index);
|
||||
}
|
||||
|
@ -115,6 +115,7 @@ oop Universe::_the_min_jint_string = NULL;
|
||||
LatestMethodCache* Universe::_finalizer_register_cache = NULL;
|
||||
LatestMethodCache* Universe::_loader_addClass_cache = NULL;
|
||||
LatestMethodCache* Universe::_pd_implies_cache = NULL;
|
||||
LatestMethodCache* Universe::_throw_illegal_access_error_cache = NULL;
|
||||
oop Universe::_out_of_memory_error_java_heap = NULL;
|
||||
oop Universe::_out_of_memory_error_metaspace = NULL;
|
||||
oop Universe::_out_of_memory_error_class_metaspace = NULL;
|
||||
@ -130,7 +131,6 @@ oop Universe::_virtual_machine_error_instance = NULL;
|
||||
oop Universe::_vm_exception = NULL;
|
||||
oop Universe::_allocation_context_notification_obj = NULL;
|
||||
|
||||
Method* Universe::_throw_illegal_access_error = NULL;
|
||||
Array<int>* Universe::_the_empty_int_array = NULL;
|
||||
Array<u2>* Universe::_the_empty_short_array = NULL;
|
||||
Array<Klass*>* Universe::_the_empty_klass_array = NULL;
|
||||
@ -236,6 +236,7 @@ void Universe::serialize(SerializeClosure* f, bool do_all) {
|
||||
_finalizer_register_cache->serialize(f);
|
||||
_loader_addClass_cache->serialize(f);
|
||||
_pd_implies_cache->serialize(f);
|
||||
_throw_illegal_access_error_cache->serialize(f);
|
||||
}
|
||||
|
||||
void Universe::check_alignment(uintx size, uintx alignment, const char* name) {
|
||||
@ -664,6 +665,7 @@ jint universe_init() {
|
||||
Universe::_finalizer_register_cache = new LatestMethodCache();
|
||||
Universe::_loader_addClass_cache = new LatestMethodCache();
|
||||
Universe::_pd_implies_cache = new LatestMethodCache();
|
||||
Universe::_throw_illegal_access_error_cache = new LatestMethodCache();
|
||||
|
||||
if (UseSharedSpaces) {
|
||||
// Read the data structures supporting the shared spaces (shared
|
||||
@ -1016,7 +1018,8 @@ bool universe_post_init() {
|
||||
tty->print_cr("Unable to link/verify Unsafe.throwIllegalAccessError method");
|
||||
return false; // initialization failed (cannot throw exception yet)
|
||||
}
|
||||
Universe::_throw_illegal_access_error = m;
|
||||
Universe::_throw_illegal_access_error_cache->init(
|
||||
SystemDictionary::misc_Unsafe_klass(), m);
|
||||
|
||||
// Setup method for registering loaded classes in class loader vector
|
||||
InstanceKlass::cast(SystemDictionary::ClassLoader_klass())->link_class(CHECK_false);
|
||||
@ -1042,7 +1045,7 @@ bool universe_post_init() {
|
||||
return false; // initialization failed
|
||||
}
|
||||
Universe::_pd_implies_cache->init(
|
||||
SystemDictionary::ProtectionDomain_klass(), m);;
|
||||
SystemDictionary::ProtectionDomain_klass(), m);
|
||||
}
|
||||
|
||||
// This needs to be done before the first scavenge/gc, since
|
||||
|
@ -148,8 +148,7 @@ class Universe: AllStatic {
|
||||
static LatestMethodCache* _finalizer_register_cache; // static method for registering finalizable objects
|
||||
static LatestMethodCache* _loader_addClass_cache; // method for registering loaded classes in class loader vector
|
||||
static LatestMethodCache* _pd_implies_cache; // method for checking protection domain attributes
|
||||
|
||||
static Method* _throw_illegal_access_error;
|
||||
static LatestMethodCache* _throw_illegal_access_error_cache; // Unsafe.throwIllegalAccessError() method
|
||||
|
||||
// preallocated error objects (no backtrace)
|
||||
static oop _out_of_memory_error_java_heap;
|
||||
@ -305,6 +304,7 @@ class Universe: AllStatic {
|
||||
static Method* loader_addClass_method() { return _loader_addClass_cache->get_method(); }
|
||||
|
||||
static Method* protection_domain_implies_method() { return _pd_implies_cache->get_method(); }
|
||||
static Method* throw_illegal_access_error() { return _throw_illegal_access_error_cache->get_method(); }
|
||||
|
||||
static oop null_ptr_exception_instance() { return _null_ptr_exception_instance; }
|
||||
static oop arithmetic_exception_instance() { return _arithmetic_exception_instance; }
|
||||
@ -314,8 +314,6 @@ class Universe: AllStatic {
|
||||
static inline oop allocation_context_notification_obj();
|
||||
static inline void set_allocation_context_notification_obj(oop obj);
|
||||
|
||||
static Method* throw_illegal_access_error() { return _throw_illegal_access_error; }
|
||||
|
||||
static Array<int>* the_empty_int_array() { return _the_empty_int_array; }
|
||||
static Array<u2>* the_empty_short_array() { return _the_empty_short_array; }
|
||||
static Array<Method*>* the_empty_method_array() { return _the_empty_method_array; }
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 1997, 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
|
||||
@ -71,10 +71,13 @@ Klass* ArrayKlass::find_field(Symbol* name, Symbol* sig, fieldDescriptor* fd) co
|
||||
return super()->find_field(name, sig, fd);
|
||||
}
|
||||
|
||||
Method* ArrayKlass::uncached_lookup_method(Symbol* name, Symbol* signature, MethodLookupMode mode) const {
|
||||
Method* ArrayKlass::uncached_lookup_method(Symbol* name, Symbol* signature, OverpassLookupMode overpass_mode) const {
|
||||
// There are no methods in an array klass but the super class (Object) has some
|
||||
assert(super(), "super klass must be present");
|
||||
return super()->uncached_lookup_method(name, signature, mode);
|
||||
// Always ignore overpass methods in superclasses, although technically the
|
||||
// super klass of an array, (j.l.Object) should not have
|
||||
// any overpass methods present.
|
||||
return super()->uncached_lookup_method(name, signature, Klass::skip_overpass);
|
||||
}
|
||||
|
||||
ArrayKlass::ArrayKlass(Symbol* name) {
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 1997, 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
|
||||
@ -82,7 +82,7 @@ class ArrayKlass: public Klass {
|
||||
Klass* find_field(Symbol* name, Symbol* sig, fieldDescriptor* fd) const;
|
||||
|
||||
// Lookup operations
|
||||
Method* uncached_lookup_method(Symbol* name, Symbol* signature, MethodLookupMode mode) const;
|
||||
Method* uncached_lookup_method(Symbol* name, Symbol* signature, OverpassLookupMode overpass_mode) const;
|
||||
|
||||
// Casting from Klass*
|
||||
static ArrayKlass* cast(Klass* k) {
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 1997, 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
|
||||
@ -493,12 +493,7 @@ Symbol* ConstantPool::uncached_klass_ref_at_noresolve(int which) {
|
||||
}
|
||||
|
||||
char* ConstantPool::string_at_noresolve(int which) {
|
||||
Symbol* s = unresolved_string_at(which);
|
||||
if (s == NULL) {
|
||||
return (char*)"<pseudo-string>";
|
||||
} else {
|
||||
return unresolved_string_at(which)->as_C_string();
|
||||
}
|
||||
return unresolved_string_at(which)->as_C_string();
|
||||
}
|
||||
|
||||
BasicType ConstantPool::basic_type_for_signature_at(int which) {
|
||||
@ -1828,7 +1823,7 @@ void ConstantPool::patch_resolved_references(GrowableArray<Handle>* cp_patches)
|
||||
// explicitly, because it may require scavenging.
|
||||
int obj_index = cp_to_object_index(index);
|
||||
pseudo_string_at_put(index, obj_index, patch());
|
||||
DEBUG_ONLY(cp_patches->at_put(index, Handle());)
|
||||
DEBUG_ONLY(cp_patches->at_put(index, Handle());)
|
||||
}
|
||||
}
|
||||
#ifdef ASSERT
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 1997, 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
|
||||
@ -48,17 +48,21 @@ class SymbolHashMap;
|
||||
class CPSlot VALUE_OBJ_CLASS_SPEC {
|
||||
intptr_t _ptr;
|
||||
public:
|
||||
enum TagBits { _resolved_value = 0, _symbol_bit = 1, _pseudo_bit = 2, _symbol_mask = 3 };
|
||||
|
||||
CPSlot(intptr_t ptr): _ptr(ptr) {}
|
||||
CPSlot(Klass* ptr): _ptr((intptr_t)ptr) {}
|
||||
CPSlot(Symbol* ptr): _ptr((intptr_t)ptr | 1) {}
|
||||
CPSlot(Symbol* ptr): _ptr((intptr_t)ptr | _symbol_bit) {}
|
||||
CPSlot(Symbol* ptr, int tag_bits): _ptr((intptr_t)ptr | tag_bits) {}
|
||||
|
||||
intptr_t value() { return _ptr; }
|
||||
bool is_resolved() { return (_ptr & 1) == 0; }
|
||||
bool is_unresolved() { return (_ptr & 1) == 1; }
|
||||
bool is_resolved() { return (_ptr & _symbol_bit ) == _resolved_value; }
|
||||
bool is_unresolved() { return (_ptr & _symbol_bit ) != _resolved_value; }
|
||||
bool is_pseudo_string() { return (_ptr & _symbol_mask) == _symbol_bit + _pseudo_bit; }
|
||||
|
||||
Symbol* get_symbol() {
|
||||
assert(is_unresolved(), "bad call");
|
||||
return (Symbol*)(_ptr & ~1);
|
||||
return (Symbol*)(_ptr & ~_symbol_mask);
|
||||
}
|
||||
Klass* get_klass() {
|
||||
assert(is_resolved(), "bad call");
|
||||
@ -261,7 +265,7 @@ class ConstantPool : public Metadata {
|
||||
|
||||
void unresolved_string_at_put(int which, Symbol* s) {
|
||||
release_tag_at_put(which, JVM_CONSTANT_String);
|
||||
*symbol_at_addr(which) = s;
|
||||
slot_at_put(which, CPSlot(s, CPSlot::_symbol_bit));
|
||||
}
|
||||
|
||||
void int_at_put(int which, jint i) {
|
||||
@ -405,20 +409,18 @@ class ConstantPool : public Metadata {
|
||||
// use pseudo-strings to link themselves to related metaobjects.
|
||||
|
||||
bool is_pseudo_string_at(int which) {
|
||||
// A pseudo string is a string that doesn't have a symbol in the cpSlot
|
||||
return unresolved_string_at(which) == NULL;
|
||||
assert(tag_at(which).is_string(), "Corrupted constant pool");
|
||||
return slot_at(which).is_pseudo_string();
|
||||
}
|
||||
|
||||
oop pseudo_string_at(int which, int obj_index) {
|
||||
assert(tag_at(which).is_string(), "Corrupted constant pool");
|
||||
assert(unresolved_string_at(which) == NULL, "shouldn't have symbol");
|
||||
assert(is_pseudo_string_at(which), "must be a pseudo-string");
|
||||
oop s = resolved_references()->obj_at(obj_index);
|
||||
return s;
|
||||
}
|
||||
|
||||
oop pseudo_string_at(int which) {
|
||||
assert(tag_at(which).is_string(), "Corrupted constant pool");
|
||||
assert(unresolved_string_at(which) == NULL, "shouldn't have symbol");
|
||||
assert(is_pseudo_string_at(which), "must be a pseudo-string");
|
||||
int obj_index = cp_to_object_index(which);
|
||||
oop s = resolved_references()->obj_at(obj_index);
|
||||
return s;
|
||||
@ -426,7 +428,8 @@ class ConstantPool : public Metadata {
|
||||
|
||||
void pseudo_string_at_put(int which, int obj_index, oop x) {
|
||||
assert(tag_at(which).is_string(), "Corrupted constant pool");
|
||||
unresolved_string_at_put(which, NULL); // indicates patched string
|
||||
Symbol* sym = unresolved_string_at(which);
|
||||
slot_at_put(which, CPSlot(sym, (CPSlot::_symbol_bit | CPSlot::_pseudo_bit)));
|
||||
string_at_put(which, obj_index, x); // this works just fine
|
||||
}
|
||||
|
||||
@ -443,15 +446,14 @@ class ConstantPool : public Metadata {
|
||||
|
||||
Symbol* unresolved_string_at(int which) {
|
||||
assert(tag_at(which).is_string(), "Corrupted constant pool");
|
||||
Symbol* s = *symbol_at_addr(which);
|
||||
return s;
|
||||
Symbol* sym = slot_at(which).get_symbol();
|
||||
return sym;
|
||||
}
|
||||
|
||||
// Returns an UTF8 for a CONSTANT_String entry at a given index.
|
||||
// UTF8 char* representation was chosen to avoid conversion of
|
||||
// java_lang_Strings at resolved entries into Symbol*s
|
||||
// or vice versa.
|
||||
// Caller is responsible for checking for pseudo-strings.
|
||||
char* string_at_noresolve(int which);
|
||||
|
||||
jint name_and_type_at(int which) {
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 1997, 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
|
||||
@ -1416,18 +1416,21 @@ static int binary_search(Array<Method*>* methods, Symbol* name) {
|
||||
|
||||
// find_method looks up the name/signature in the local methods array
|
||||
Method* InstanceKlass::find_method(Symbol* name, Symbol* signature) const {
|
||||
return find_method_impl(name, signature, false);
|
||||
return find_method_impl(name, signature, find_overpass, find_static);
|
||||
}
|
||||
|
||||
Method* InstanceKlass::find_method_impl(Symbol* name, Symbol* signature, bool skipping_overpass) const {
|
||||
return InstanceKlass::find_method_impl(methods(), name, signature, skipping_overpass, false);
|
||||
Method* InstanceKlass::find_method_impl(Symbol* name, Symbol* signature,
|
||||
OverpassLookupMode overpass_mode, StaticLookupMode static_mode) const {
|
||||
return InstanceKlass::find_method_impl(methods(), name, signature, overpass_mode, static_mode);
|
||||
}
|
||||
|
||||
// find_instance_method looks up the name/signature in the local methods array
|
||||
// and skips over static methods
|
||||
Method* InstanceKlass::find_instance_method(
|
||||
Array<Method*>* methods, Symbol* name, Symbol* signature) {
|
||||
Method* meth = InstanceKlass::find_method_impl(methods, name, signature, false, true);
|
||||
Method* meth = InstanceKlass::find_method_impl(methods, name, signature,
|
||||
find_overpass, skip_static);
|
||||
assert(((meth == NULL) || !meth->is_static()), "find_instance_method should have skipped statics");
|
||||
return meth;
|
||||
}
|
||||
|
||||
@ -1440,12 +1443,12 @@ Method* InstanceKlass::find_instance_method(Symbol* name, Symbol* signature) {
|
||||
// find_method looks up the name/signature in the local methods array
|
||||
Method* InstanceKlass::find_method(
|
||||
Array<Method*>* methods, Symbol* name, Symbol* signature) {
|
||||
return InstanceKlass::find_method_impl(methods, name, signature, false, false);
|
||||
return InstanceKlass::find_method_impl(methods, name, signature, find_overpass, find_static);
|
||||
}
|
||||
|
||||
Method* InstanceKlass::find_method_impl(
|
||||
Array<Method*>* methods, Symbol* name, Symbol* signature, bool skipping_overpass, bool skipping_static) {
|
||||
int hit = find_method_index(methods, name, signature, skipping_overpass, skipping_static);
|
||||
Array<Method*>* methods, Symbol* name, Symbol* signature, OverpassLookupMode overpass_mode, StaticLookupMode static_mode) {
|
||||
int hit = find_method_index(methods, name, signature, overpass_mode, static_mode);
|
||||
return hit >= 0 ? methods->at(hit): NULL;
|
||||
}
|
||||
|
||||
@ -1463,7 +1466,9 @@ bool InstanceKlass::method_matches(Method* m, Symbol* signature, bool skipping_o
|
||||
// is important during method resolution to prefer a static method, for example,
|
||||
// over an overpass method.
|
||||
int InstanceKlass::find_method_index(
|
||||
Array<Method*>* methods, Symbol* name, Symbol* signature, bool skipping_overpass, bool skipping_static) {
|
||||
Array<Method*>* methods, Symbol* name, Symbol* signature, OverpassLookupMode overpass_mode, StaticLookupMode static_mode) {
|
||||
bool skipping_overpass = (overpass_mode == skip_overpass);
|
||||
bool skipping_static = (static_mode == skip_static);
|
||||
int hit = binary_search(methods, name);
|
||||
if (hit != -1) {
|
||||
Method* m = methods->at(hit);
|
||||
@ -1489,7 +1494,7 @@ int InstanceKlass::find_method_index(
|
||||
}
|
||||
// not found
|
||||
#ifdef ASSERT
|
||||
int index = skipping_overpass || skipping_static ? -1 : linear_search(methods, name, signature);
|
||||
int index = (skipping_overpass || skipping_static) ? -1 : linear_search(methods, name, signature);
|
||||
assert(index == -1, err_msg("binary search should have found entry %d", index));
|
||||
#endif
|
||||
}
|
||||
@ -1515,16 +1520,16 @@ int InstanceKlass::find_method_by_name(
|
||||
|
||||
// uncached_lookup_method searches both the local class methods array and all
|
||||
// superclasses methods arrays, skipping any overpass methods in superclasses.
|
||||
Method* InstanceKlass::uncached_lookup_method(Symbol* name, Symbol* signature, MethodLookupMode mode) const {
|
||||
MethodLookupMode lookup_mode = mode;
|
||||
Method* InstanceKlass::uncached_lookup_method(Symbol* name, Symbol* signature, OverpassLookupMode overpass_mode) const {
|
||||
OverpassLookupMode overpass_local_mode = overpass_mode;
|
||||
Klass* klass = const_cast<InstanceKlass*>(this);
|
||||
while (klass != NULL) {
|
||||
Method* method = InstanceKlass::cast(klass)->find_method_impl(name, signature, (lookup_mode == skip_overpass));
|
||||
Method* method = InstanceKlass::cast(klass)->find_method_impl(name, signature, overpass_local_mode, find_static);
|
||||
if (method != NULL) {
|
||||
return method;
|
||||
}
|
||||
klass = InstanceKlass::cast(klass)->super();
|
||||
lookup_mode = skip_overpass; // Always ignore overpass methods in superclasses
|
||||
overpass_local_mode = skip_overpass; // Always ignore overpass methods in superclasses
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
@ -1554,7 +1559,7 @@ Method* InstanceKlass::lookup_method_in_ordered_interfaces(Symbol* name,
|
||||
}
|
||||
// Look up interfaces
|
||||
if (m == NULL) {
|
||||
m = lookup_method_in_all_interfaces(name, signature, normal);
|
||||
m = lookup_method_in_all_interfaces(name, signature, find_defaults);
|
||||
}
|
||||
return m;
|
||||
}
|
||||
@ -1564,7 +1569,7 @@ Method* InstanceKlass::lookup_method_in_ordered_interfaces(Symbol* name,
|
||||
// They should only be found in the initial InterfaceMethodRef
|
||||
Method* InstanceKlass::lookup_method_in_all_interfaces(Symbol* name,
|
||||
Symbol* signature,
|
||||
MethodLookupMode mode) const {
|
||||
DefaultsLookupMode defaults_mode) const {
|
||||
Array<Klass*>* all_ifs = transitive_interfaces();
|
||||
int num_ifs = all_ifs->length();
|
||||
InstanceKlass *ik = NULL;
|
||||
@ -1572,7 +1577,7 @@ Method* InstanceKlass::lookup_method_in_all_interfaces(Symbol* name,
|
||||
ik = InstanceKlass::cast(all_ifs->at(i));
|
||||
Method* m = ik->lookup_method(name, signature);
|
||||
if (m != NULL && m->is_public() && !m->is_static() &&
|
||||
((mode != skip_defaults) || !m->is_default_method())) {
|
||||
((defaults_mode != skip_defaults) || !m->is_default_method())) {
|
||||
return m;
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 1997, 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
|
||||
@ -499,14 +499,15 @@ class InstanceKlass: public Klass {
|
||||
static bool method_matches(Method* m, Symbol* signature, bool skipping_overpass, bool skipping_static);
|
||||
|
||||
// find a local method index in default_methods (returns -1 if not found)
|
||||
static int find_method_index(Array<Method*>* methods, Symbol* name, Symbol* signature, bool skipping_overpass, bool skipping_static);
|
||||
static int find_method_index(Array<Method*>* methods, Symbol* name, Symbol* signature,
|
||||
OverpassLookupMode overpass_mode, StaticLookupMode static_mode);
|
||||
|
||||
// lookup operation (returns NULL if not found)
|
||||
Method* uncached_lookup_method(Symbol* name, Symbol* signature, MethodLookupMode mode) const;
|
||||
Method* uncached_lookup_method(Symbol* name, Symbol* signature, OverpassLookupMode overpass_mode) const;
|
||||
|
||||
// lookup a method in all the interfaces that this class implements
|
||||
// (returns NULL if not found)
|
||||
Method* lookup_method_in_all_interfaces(Symbol* name, Symbol* signature, MethodLookupMode mode) const;
|
||||
Method* lookup_method_in_all_interfaces(Symbol* name, Symbol* signature, DefaultsLookupMode defaults_mode) const;
|
||||
|
||||
// lookup a method in local defaults then in all interfaces
|
||||
// (returns NULL if not found)
|
||||
@ -1058,8 +1059,10 @@ private:
|
||||
Klass* array_klass_impl(bool or_null, TRAPS);
|
||||
|
||||
// find a local method (returns NULL if not found)
|
||||
Method* find_method_impl(Symbol* name, Symbol* signature, bool skipping_overpass) const;
|
||||
static Method* find_method_impl(Array<Method*>* methods, Symbol* name, Symbol* signature, bool skipping_overpass, bool skipping_static);
|
||||
Method* find_method_impl(Symbol* name, Symbol* signature,
|
||||
OverpassLookupMode overpass_mode, StaticLookupMode static_mode) const;
|
||||
static Method* find_method_impl(Array<Method*>* methods, Symbol* name, Symbol* signature,
|
||||
OverpassLookupMode overpass_mode, StaticLookupMode static_mode);
|
||||
|
||||
// Free CHeap allocated fields.
|
||||
void release_C_heap_structures();
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 1997, 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
|
||||
@ -140,7 +140,7 @@ Klass* Klass::find_field(Symbol* name, Symbol* sig, fieldDescriptor* fd) const {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
Method* Klass::uncached_lookup_method(Symbol* name, Symbol* signature, MethodLookupMode mode) const {
|
||||
Method* Klass::uncached_lookup_method(Symbol* name, Symbol* signature, OverpassLookupMode overpass_mode) const {
|
||||
#ifdef ASSERT
|
||||
tty->print_cr("Error: uncached_lookup_method called on a klass oop."
|
||||
" Likely error: reflection method does not correctly"
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 1997, 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
|
||||
@ -164,7 +164,9 @@ protected:
|
||||
void* operator new(size_t size, ClassLoaderData* loader_data, size_t word_size, TRAPS) throw();
|
||||
|
||||
public:
|
||||
enum MethodLookupMode { normal, skip_overpass, skip_defaults };
|
||||
enum DefaultsLookupMode { find_defaults, skip_defaults };
|
||||
enum OverpassLookupMode { find_overpass, skip_overpass };
|
||||
enum StaticLookupMode { find_static, skip_static };
|
||||
|
||||
bool is_klass() const volatile { return true; }
|
||||
|
||||
@ -413,10 +415,10 @@ protected:
|
||||
// lookup operation for MethodLookupCache
|
||||
friend class MethodLookupCache;
|
||||
virtual Klass* find_field(Symbol* name, Symbol* signature, fieldDescriptor* fd) const;
|
||||
virtual Method* uncached_lookup_method(Symbol* name, Symbol* signature, MethodLookupMode mode) const;
|
||||
virtual Method* uncached_lookup_method(Symbol* name, Symbol* signature, OverpassLookupMode overpass_mode) const;
|
||||
public:
|
||||
Method* lookup_method(Symbol* name, Symbol* signature) const {
|
||||
return uncached_lookup_method(name, signature, normal);
|
||||
return uncached_lookup_method(name, signature, find_overpass);
|
||||
}
|
||||
|
||||
// array class with specific rank
|
||||
|
@ -649,7 +649,7 @@ bool klassVtable::needs_new_vtable_entry(methodHandle target_method,
|
||||
// this check for all access permissions.
|
||||
InstanceKlass *sk = InstanceKlass::cast(super);
|
||||
if (sk->has_miranda_methods()) {
|
||||
if (sk->lookup_method_in_all_interfaces(name, signature, Klass::normal) != NULL) {
|
||||
if (sk->lookup_method_in_all_interfaces(name, signature, Klass::find_defaults) != NULL) {
|
||||
return false; // found a matching miranda; we do not need a new entry
|
||||
}
|
||||
}
|
||||
@ -725,7 +725,7 @@ bool klassVtable::is_miranda(Method* m, Array<Method*>* class_methods,
|
||||
&& mo->method_holder() != NULL
|
||||
&& mo->method_holder()->super() != NULL)
|
||||
{
|
||||
mo = mo->method_holder()->super()->uncached_lookup_method(name, signature, Klass::normal);
|
||||
mo = mo->method_holder()->super()->uncached_lookup_method(name, signature, Klass::find_overpass);
|
||||
}
|
||||
if (mo == NULL || mo->access_flags().is_private() ) {
|
||||
// super class hierarchy does not implement it or protection is different
|
||||
@ -770,7 +770,7 @@ void klassVtable::add_new_mirandas_to_lists(
|
||||
if (is_miranda(im, class_methods, default_methods, super)) { // is it a miranda at all?
|
||||
InstanceKlass *sk = InstanceKlass::cast(super);
|
||||
// check if it is a duplicate of a super's miranda
|
||||
if (sk->lookup_method_in_all_interfaces(im->name(), im->signature(), Klass::normal) == NULL) {
|
||||
if (sk->lookup_method_in_all_interfaces(im->name(), im->signature(), Klass::find_defaults) == NULL) {
|
||||
new_mirandas->append(im);
|
||||
}
|
||||
if (all_mirandas != NULL) {
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 1999, 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 1999, 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
|
||||
@ -1351,7 +1351,6 @@ Node* LibraryCallKit::string_indexOf(Node* string_object, ciTypeArray* target_ar
|
||||
Node* cache = __ ConI(cache_i);
|
||||
Node* md2 = __ ConI(md2_i);
|
||||
Node* lastChar = __ ConI(target_array->char_at(target_length - 1));
|
||||
Node* targetCount = __ ConI(target_length);
|
||||
Node* targetCountLess1 = __ ConI(target_length - 1);
|
||||
Node* targetOffset = __ ConI(targetOffset_i);
|
||||
Node* sourceEnd = __ SubI(__ AddI(sourceOffset, sourceCount), targetCountLess1);
|
||||
@ -1408,8 +1407,6 @@ bool LibraryCallKit::inline_string_indexOf() {
|
||||
Node* arg = argument(1);
|
||||
|
||||
Node* result;
|
||||
// Disable the use of pcmpestri until it can be guaranteed that
|
||||
// the load doesn't cross into the uncommited space.
|
||||
if (Matcher::has_match_rule(Op_StrIndexOf) &&
|
||||
UseSSE42Intrinsics) {
|
||||
// Generate SSE4.2 version of indexOf
|
||||
@ -1421,9 +1418,6 @@ bool LibraryCallKit::inline_string_indexOf() {
|
||||
return true;
|
||||
}
|
||||
|
||||
ciInstanceKlass* str_klass = env()->String_klass();
|
||||
const TypeOopPtr* string_type = TypeOopPtr::make_from_klass(str_klass);
|
||||
|
||||
// Make the merge point
|
||||
RegionNode* result_rgn = new RegionNode(4);
|
||||
Node* result_phi = new PhiNode(result_rgn, TypeInt::INT);
|
||||
|
@ -2475,7 +2475,7 @@ void Scheduling::DoScheduling() {
|
||||
if( iop == Op_Con ) continue; // Do not schedule Top
|
||||
if( iop == Op_Node && // Do not schedule PhiNodes, ProjNodes
|
||||
mach->pipeline() == MachNode::pipeline_class() &&
|
||||
!n->is_SpillCopy() ) // Breakpoints, Prolog, etc
|
||||
!n->is_SpillCopy() && !n->is_MachMerge() ) // Breakpoints, Prolog, etc
|
||||
continue;
|
||||
break; // Funny loop structure to be sure...
|
||||
}
|
||||
|
@ -428,6 +428,7 @@ int PhaseChaitin::possibly_merge_multidef(Node *n, uint k, Block *block, RegToDe
|
||||
// Insert the merge node into the block before the first use.
|
||||
uint use_index = block->find_node(reg2defuse.at(reg).first_use());
|
||||
block->insert_node(merge, use_index++);
|
||||
_cfg.map_node_to_block(merge, block);
|
||||
|
||||
// Let the allocator know about the new node, use the same lrg
|
||||
_lrg_map.extend(merge->_idx, lrg);
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 1997, 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
|
||||
@ -300,6 +300,48 @@ JVM_LEAF(jlong, JVM_NanoTime(JNIEnv *env, jclass ignored))
|
||||
return os::javaTimeNanos();
|
||||
JVM_END
|
||||
|
||||
// The function below is actually exposed by sun.misc.VM and not
|
||||
// java.lang.System, but we choose to keep it here so that it stays next
|
||||
// to JVM_CurrentTimeMillis and JVM_NanoTime
|
||||
|
||||
const jlong MAX_DIFF_SECS = 0x0100000000LL; // 2^32
|
||||
const jlong MIN_DIFF_SECS = -MAX_DIFF_SECS; // -2^32
|
||||
|
||||
JVM_LEAF(jlong, JVM_GetNanoTimeAdjustment(JNIEnv *env, jclass ignored, jlong offset_secs))
|
||||
JVMWrapper("JVM_GetNanoTimeAdjustment");
|
||||
jlong seconds;
|
||||
jlong nanos;
|
||||
|
||||
os::javaTimeSystemUTC(seconds, nanos);
|
||||
|
||||
// We're going to verify that the result can fit in a long.
|
||||
// For that we need the difference in seconds between 'seconds'
|
||||
// and 'offset_secs' to be such that:
|
||||
// |seconds - offset_secs| < (2^63/10^9)
|
||||
// We're going to approximate 10^9 ~< 2^30 (1000^3 ~< 1024^3)
|
||||
// which makes |seconds - offset_secs| < 2^33
|
||||
// and we will prefer +/- 2^32 as the maximum acceptable diff
|
||||
// as 2^32 has a more natural feel than 2^33...
|
||||
//
|
||||
// So if |seconds - offset_secs| >= 2^32 - we return a special
|
||||
// sentinel value (-1) which the caller should take as an
|
||||
// exception value indicating that the offset given to us is
|
||||
// too far from range of the current time - leading to too big
|
||||
// a nano adjustment. The caller is expected to recover by
|
||||
// computing a more accurate offset and calling this method
|
||||
// again. (For the record 2^32 secs is ~136 years, so that
|
||||
// should rarely happen)
|
||||
//
|
||||
jlong diff = seconds - offset_secs;
|
||||
if (diff >= MAX_DIFF_SECS || diff <= MIN_DIFF_SECS) {
|
||||
return -1; // sentinel value: the offset is too far off the target
|
||||
}
|
||||
|
||||
// return the adjustment. If you compute a time by adding
|
||||
// this number of nanoseconds along with the number of seconds
|
||||
// in the offset you should get the current UTC time.
|
||||
return (diff * (jlong)1000000000) + nanos;
|
||||
JVM_END
|
||||
|
||||
JVM_ENTRY(void, JVM_ArrayCopy(JNIEnv *env, jclass ignored, jobject src, jint src_pos,
|
||||
jobject dst, jint dst_pos, jint length))
|
||||
@ -1167,7 +1209,7 @@ JVM_ENTRY(jobject, JVM_DoPrivileged(JNIEnv *env, jclass cls, jobject action, job
|
||||
Method* m_oop = object->klass()->uncached_lookup_method(
|
||||
vmSymbols::run_method_name(),
|
||||
vmSymbols::void_object_signature(),
|
||||
Klass::normal);
|
||||
Klass::find_overpass);
|
||||
methodHandle m (THREAD, m_oop);
|
||||
if (m.is_null() || !m->is_method() || !m()->is_public() || m()->is_static()) {
|
||||
THROW_MSG_0(vmSymbols::java_lang_InternalError(), "No run method");
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 1997, 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
|
||||
@ -131,6 +131,9 @@ JVM_CurrentTimeMillis(JNIEnv *env, jclass ignored);
|
||||
JNIEXPORT jlong JNICALL
|
||||
JVM_NanoTime(JNIEnv *env, jclass ignored);
|
||||
|
||||
JNIEXPORT jlong JNICALL
|
||||
JVM_GetNanoTimeAdjustment(JNIEnv *env, jclass ignored, jlong offset_secs);
|
||||
|
||||
JNIEXPORT void JNICALL
|
||||
JVM_ArrayCopy(JNIEnv *env, jclass ignored, jobject src, jint src_pos,
|
||||
jobject dst, jint dst_pos, jint length);
|
||||
|
@ -3376,7 +3376,9 @@ void VM_RedefineClasses::AdjustCpoolCacheAndVtable::do_klass(Klass* k) {
|
||||
// not yet in the vtable, because the vtable setup is in progress.
|
||||
// This must be done after we adjust the default_methods and
|
||||
// default_vtable_indices for methods already in the vtable.
|
||||
// If redefining Unsafe, walk all the vtables looking for entries.
|
||||
if (ik->vtable_length() > 0 && (_the_class_oop->is_interface()
|
||||
|| _the_class_oop == SystemDictionary::misc_Unsafe_klass()
|
||||
|| ik->is_subtype_of(_the_class_oop))) {
|
||||
// ik->vtable() creates a wrapper object; rm cleans it up
|
||||
ResourceMark rm(_thread);
|
||||
@ -3396,7 +3398,9 @@ void VM_RedefineClasses::AdjustCpoolCacheAndVtable::do_klass(Klass* k) {
|
||||
// interface, then we have to call adjust_method_entries() for
|
||||
// every InstanceKlass that has an itable since there isn't a
|
||||
// subclass relationship between an interface and an InstanceKlass.
|
||||
// If redefining Unsafe, walk all the itables looking for entries.
|
||||
if (ik->itable_length() > 0 && (_the_class_oop->is_interface()
|
||||
|| _the_class_oop == SystemDictionary::misc_Unsafe_klass()
|
||||
|| ik->is_subclass_of(_the_class_oop))) {
|
||||
// ik->itable() creates a wrapper object; rm cleans it up
|
||||
ResourceMark rm(_thread);
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2000, 2012, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2000, 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
|
||||
@ -405,6 +405,8 @@ bool MethodComparator::pool_constants_same(int cpi_old, int cpi_new) {
|
||||
if (strcmp(_old_cp->string_at_noresolve(cpi_old),
|
||||
_new_cp->string_at_noresolve(cpi_new)) != 0)
|
||||
return false;
|
||||
if (_old_cp->is_pseudo_string_at(cpi_old) || _new_cp->is_pseudo_string_at(cpi_new))
|
||||
return (_old_cp->is_pseudo_string_at(cpi_old) == _new_cp->is_pseudo_string_at(cpi_new));
|
||||
} else if (tag_old.is_klass() || tag_old.is_unresolved_klass()) {
|
||||
// tag_old should be klass - 4881222
|
||||
if (! (tag_new.is_unresolved_klass() || tag_new.is_klass()))
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 1997, 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
|
||||
@ -393,7 +393,7 @@ address NativeLookup::base_library_lookup(const char* class_name, const char* me
|
||||
|
||||
// Find method and invoke standard lookup
|
||||
methodHandle method (THREAD,
|
||||
klass->uncached_lookup_method(m_name, s_name, Klass::normal));
|
||||
klass->uncached_lookup_method(m_name, s_name, Klass::find_overpass));
|
||||
address result = lookup(method, in_base_library, CATCH);
|
||||
assert(in_base_library, "must be in basic library");
|
||||
guarantee(result != NULL, "must be non NULL");
|
||||
|
@ -1127,7 +1127,7 @@ static void no_shared_spaces(const char* message) {
|
||||
#endif
|
||||
|
||||
intx Arguments::scaled_compile_threshold(intx threshold, double scale) {
|
||||
if (scale == 1.0 || scale < 0.0) {
|
||||
if (scale == 1.0 || scale <= 0.0) {
|
||||
return threshold;
|
||||
} else {
|
||||
return (intx)(threshold * scale);
|
||||
@ -1143,7 +1143,7 @@ intx Arguments::scaled_freq_log(intx freq_log, double scale) {
|
||||
|
||||
// Check value to avoid calculating log2 of 0.
|
||||
if (scale == 0.0) {
|
||||
return 1;
|
||||
return freq_log;
|
||||
}
|
||||
|
||||
intx scaled_freq = scaled_compile_threshold((intx)1 << freq_log, scale);
|
||||
@ -3479,8 +3479,10 @@ jint Arguments::finalize_vm_init_args(SysClassPath* scp_p, bool scp_assembly_req
|
||||
set_mode_flags(_int);
|
||||
}
|
||||
|
||||
if ((TieredCompilation && CompileThresholdScaling == 0)
|
||||
|| (!TieredCompilation && scaled_compile_threshold(CompileThreshold) == 0)) {
|
||||
// CompileThresholdScaling == 0.0 is same as -Xint: Disable compilation (enable interpreter-only mode),
|
||||
// but like -Xint, leave compilation thresholds unaffected.
|
||||
// With tiered compilation disabled, setting CompileThreshold to 0 disables compilation as well.
|
||||
if ((CompileThresholdScaling == 0.0) || (!TieredCompilation && CompileThreshold == 0)) {
|
||||
set_mode_flags(_int);
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 1997, 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
|
||||
@ -173,10 +173,10 @@ class os: AllStatic {
|
||||
static jlong javaTimeMillis();
|
||||
static jlong javaTimeNanos();
|
||||
static void javaTimeNanos_info(jvmtiTimerInfo *info_ptr);
|
||||
static void javaTimeSystemUTC(jlong &seconds, jlong &nanos);
|
||||
static void run_periodic_checks();
|
||||
static bool supports_monotonic_clock();
|
||||
|
||||
|
||||
// Returns the elapsed time in seconds since the vm started.
|
||||
static double elapsedTime();
|
||||
|
||||
|
@ -84,6 +84,13 @@ public class CheckCompileThresholdScaling {
|
||||
"-XX:CompileThresholdScaling=0.75",
|
||||
"-version"
|
||||
},
|
||||
{
|
||||
"-XX:-TieredCompilation",
|
||||
"-XX:+PrintFlagsFinal",
|
||||
"-XX:CompileThreshold=1000",
|
||||
"-XX:CompileThresholdScaling=0.0",
|
||||
"-version"
|
||||
},
|
||||
{
|
||||
"-XX:-TieredCompilation",
|
||||
"-XX:+PrintFlagsFinal",
|
||||
@ -107,6 +114,11 @@ public class CheckCompileThresholdScaling {
|
||||
"intx CompileThreshold := 750 {pd product}",
|
||||
"double CompileThresholdScaling := 0.750000 {product}"
|
||||
},
|
||||
{
|
||||
"intx CompileThreshold := 1000 {pd product}",
|
||||
"double CompileThresholdScaling := 0.000000 {product}",
|
||||
"interpreted mode"
|
||||
},
|
||||
{
|
||||
"intx CompileThreshold := 0 {pd product}",
|
||||
"double CompileThresholdScaling := 0.750000 {product}",
|
||||
@ -295,21 +307,21 @@ public class CheckCompileThresholdScaling {
|
||||
"double CompileThresholdScaling := 2.000000 {product}"
|
||||
},
|
||||
{
|
||||
"intx Tier0BackedgeNotifyFreqLog := 0 {product}",
|
||||
"intx Tier0InvokeNotifyFreqLog := 0 {product}",
|
||||
"intx Tier23InlineeNotifyFreqLog := 0 {product}",
|
||||
"intx Tier2BackedgeNotifyFreqLog := 0 {product}",
|
||||
"intx Tier2InvokeNotifyFreqLog := 0 {product}",
|
||||
"intx Tier3BackEdgeThreshold := 0 {product}",
|
||||
"intx Tier3BackedgeNotifyFreqLog := 0 {product}",
|
||||
"intx Tier3CompileThreshold := 0 {product}",
|
||||
"intx Tier3InvocationThreshold := 0 {product}",
|
||||
"intx Tier3InvokeNotifyFreqLog := 0 {product}",
|
||||
"intx Tier3MinInvocationThreshold := 0 {product}",
|
||||
"intx Tier4BackEdgeThreshold := 0 {product}",
|
||||
"intx Tier4CompileThreshold := 0 {product}",
|
||||
"intx Tier4InvocationThreshold := 0 {product}",
|
||||
"intx Tier4MinInvocationThreshold := 0 {product}",
|
||||
"intx Tier0BackedgeNotifyFreqLog := 10 {product}",
|
||||
"intx Tier0InvokeNotifyFreqLog := 7 {product}",
|
||||
"intx Tier23InlineeNotifyFreqLog := 20 {product}",
|
||||
"intx Tier2BackedgeNotifyFreqLog := 14 {product}",
|
||||
"intx Tier2InvokeNotifyFreqLog := 11 {product}",
|
||||
"intx Tier3BackEdgeThreshold := 60000 {product}",
|
||||
"intx Tier3BackedgeNotifyFreqLog := 13 {product}",
|
||||
"intx Tier3CompileThreshold := 2000 {product}",
|
||||
"intx Tier3InvocationThreshold := 200 {product}",
|
||||
"intx Tier3InvokeNotifyFreqLog := 10 {product}",
|
||||
"intx Tier3MinInvocationThreshold := 100 {product}",
|
||||
"intx Tier4BackEdgeThreshold := 40000 {product}",
|
||||
"intx Tier4CompileThreshold := 15000 {product}",
|
||||
"intx Tier4InvocationThreshold := 5000 {product}",
|
||||
"intx Tier4MinInvocationThreshold := 600 {product}",
|
||||
"double CompileThresholdScaling := 0.000000 {product}",
|
||||
"interpreted mode"
|
||||
}
|
||||
|
@ -82,6 +82,9 @@ public class PrintCodeCacheRunner implements CodeCacheCLITestCase.Runner {
|
||||
ExitCode.OK,
|
||||
testCaseDescription.getTestOptions(options,
|
||||
CommandLineOptionTest.prepareBooleanFlag(
|
||||
"PrintCodeCache", printCodeCache)));
|
||||
"PrintCodeCache", printCodeCache),
|
||||
// Do not use large pages to avoid large page
|
||||
// alignment of code heaps affecting their size.
|
||||
"-XX:-UseLargePages"));
|
||||
}
|
||||
}
|
||||
|
@ -36,7 +36,7 @@ public class CodeCacheStressRunner {
|
||||
try {
|
||||
// adjust timeout and substract vm init and exit time
|
||||
long timeout = Utils.adjustTimeout(Utils.DEFAULT_TEST_TIMEOUT);
|
||||
timeout *= 0.9;
|
||||
timeout *= 0.8;
|
||||
new TimeLimitedRunner(timeout, 2.0d, this::test).call();
|
||||
} catch (Exception e) {
|
||||
throw new Error("Exception occurred during test execution", e);
|
||||
|
@ -77,7 +77,7 @@ public class OverloadCompileQueueTest implements Runnable {
|
||||
}
|
||||
|
||||
public OverloadCompileQueueTest() {
|
||||
Helper.startInfiniteLoopThread(this::lockUnlock);
|
||||
Helper.startInfiniteLoopThread(this::lockUnlock, 100L);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -99,8 +99,9 @@ public class OverloadCompileQueueTest implements Runnable {
|
||||
|
||||
private void lockUnlock() {
|
||||
try {
|
||||
int sleep = Helper.RNG.nextInt(MAX_SLEEP);
|
||||
Helper.WHITE_BOX.lockCompilation();
|
||||
Thread.sleep(Helper.RNG.nextInt(MAX_SLEEP));
|
||||
Thread.sleep(sleep);
|
||||
} catch (InterruptedException e) {
|
||||
throw new Error("TESTBUG: lockUnlocker thread was unexpectedly interrupted", e);
|
||||
} finally {
|
||||
|
@ -26,7 +26,6 @@
|
||||
* @bug 8042235
|
||||
* @summary redefining method used by multiple MethodHandles crashes VM
|
||||
* @compile -XDignore.symbol.file RedefineMethodUsedByMultipleMethodHandles.java
|
||||
* @ignore 7076820
|
||||
* @run main RedefineMethodUsedByMultipleMethodHandles
|
||||
*/
|
||||
|
||||
|
@ -21,12 +21,15 @@
|
||||
* questions.
|
||||
*/
|
||||
|
||||
import java.io.PrintWriter;
|
||||
import java.io.File;
|
||||
|
||||
import com.oracle.java.testlibrary.*;
|
||||
|
||||
/*
|
||||
* @test CheckCompileCommandOption
|
||||
* @bug 8055286 8056964 8059847
|
||||
* @summary "Checks parsing of -XX:+CompileCommand=option"
|
||||
* @bug 8055286 8056964 8059847 8069035
|
||||
* @summary "Checks parsing of -XX:CompileCommand=option"
|
||||
* @library /testlibrary
|
||||
* @run main CheckCompileCommandOption
|
||||
*/
|
||||
@ -45,38 +48,69 @@ public class CheckCompileCommandOption {
|
||||
// have the the following types: intx, uintx, bool, ccstr,
|
||||
// ccstrlist, and double.
|
||||
|
||||
private static final String[][] FILE_ARGUMENTS = {
|
||||
{
|
||||
"-XX:CompileCommandFile=" + new File(System.getProperty("test.src", "."), "command1.txt"),
|
||||
"-version"
|
||||
},
|
||||
{
|
||||
"-XX:CompileCommandFile=" + new File(System.getProperty("test.src", "."), "command2.txt"),
|
||||
"-version"
|
||||
}
|
||||
};
|
||||
|
||||
private static final String[][] FILE_EXPECTED_OUTPUT = {
|
||||
{
|
||||
"CompileCommand: option com/oracle/Test.test bool MyBoolOption1 = true",
|
||||
"CompileCommand: option com/oracle/Test.test bool MyBoolOption2 = true",
|
||||
"CompileCommand: option com/oracle/Test.test bool MyBoolOption3 = true",
|
||||
"CompileCommand: option com/oracle/Test.test bool MyBoolOption4 = true",
|
||||
"CompileCommand: option com/oracle/Test.test bool MyBoolOption5 = true",
|
||||
"CompileCommand: option com/oracle/Test.test bool MyBoolOption6 = true",
|
||||
"CompileCommand: option com/oracle/Test.test bool MyBoolOption7 = true",
|
||||
"CompileCommand: option com/oracle/Test.test bool MyBoolOption8 = true",
|
||||
"CompileCommand: option com/oracle/Test.test(I) bool MyBoolOption9 = true",
|
||||
"CompileCommand: option com/oracle/Test.test(I) bool MyBoolOption10 = true",
|
||||
"CompileCommand: option com/oracle/Test.test(I) bool MyBoolOption11 = true",
|
||||
"CompileCommand: option com/oracle/Test.test(I) bool MyBoolOption12 = true",
|
||||
"CompileCommand: option com/oracle/Test.test(I) bool MyBoolOption13 = true",
|
||||
"CompileCommand: option com/oracle/Test.test(I) bool MyBoolOption14 = true",
|
||||
"CompileCommand: option com/oracle/Test.test(I) bool MyBoolOption15 = true",
|
||||
"CompileCommand: option com/oracle/Test.test(I) bool MyBoolOption16 = true"
|
||||
},
|
||||
{
|
||||
"CompileCommand: option Test.test const char* MyListOption = '_foo _bar'",
|
||||
"CompileCommand: option Test.test const char* MyStrOption = '_foo'",
|
||||
"CompileCommand: option Test.test bool MyBoolOption = false",
|
||||
"CompileCommand: option Test.test intx MyIntxOption = -1",
|
||||
"CompileCommand: option Test.test uintx MyUintxOption = 1",
|
||||
"CompileCommand: option Test.test bool MyFlag = true",
|
||||
"CompileCommand: option Test.test double MyDoubleOption = 1.123000"
|
||||
}
|
||||
};
|
||||
|
||||
private static final String[][] TYPE_1_ARGUMENTS = {
|
||||
{
|
||||
"-XX:CompileCommand=option,com/oracle/Test.test,MyBoolOption1",
|
||||
"-XX:CompileCommand=option,com/oracle/Test,test,MyBoolOption2",
|
||||
"-XX:CompileCommand=option,com.oracle.Test::test,MyBoolOption3",
|
||||
"-XX:CompileCommand=option,com/oracle/Test::test,MyBoolOption4",
|
||||
"-version"
|
||||
},
|
||||
{
|
||||
"-XX:CompileCommand=option,com/oracle/Test.test,MyBoolOption1,MyBoolOption2",
|
||||
"-version"
|
||||
},
|
||||
{
|
||||
"-XX:CompileCommand=option,com/oracle/Test,test,MyBoolOption1,MyBoolOption2",
|
||||
"-XX:CompileCommand=option,com/oracle/Test.test,MyBoolOption5,MyBoolOption6",
|
||||
"-XX:CompileCommand=option,com/oracle/Test,test,MyBoolOption7,MyBoolOption8",
|
||||
"-version"
|
||||
}
|
||||
};
|
||||
|
||||
private static final String[][] TYPE_1_EXPECTED_OUTPUTS = {
|
||||
{
|
||||
"CompilerOracle: option com/oracle/Test.test bool MyBoolOption1 = true",
|
||||
"CompilerOracle: option com/oracle/Test.test bool MyBoolOption2 = true",
|
||||
"CompilerOracle: option com/oracle/Test.test bool MyBoolOption3 = true",
|
||||
"CompilerOracle: option com/oracle/Test.test bool MyBoolOption4 = true"
|
||||
},
|
||||
{
|
||||
"CompilerOracle: option com/oracle/Test.test bool MyBoolOption1 = true",
|
||||
"CompilerOracle: option com/oracle/Test.test bool MyBoolOption2 = true",
|
||||
},
|
||||
{
|
||||
"CompilerOracle: option com/oracle/Test.test bool MyBoolOption1 = true",
|
||||
"CompilerOracle: option com/oracle/Test.test bool MyBoolOption2 = true",
|
||||
"CompileCommand: option com/oracle/Test.test bool MyBoolOption1 = true",
|
||||
"CompileCommand: option com/oracle/Test.test bool MyBoolOption2 = true",
|
||||
"CompileCommand: option com/oracle/Test.test bool MyBoolOption3 = true",
|
||||
"CompileCommand: option com/oracle/Test.test bool MyBoolOption4 = true",
|
||||
"CompileCommand: option com/oracle/Test.test bool MyBoolOption5 = true",
|
||||
"CompileCommand: option com/oracle/Test.test bool MyBoolOption6 = true",
|
||||
"CompileCommand: option com/oracle/Test.test bool MyBoolOption7 = true",
|
||||
"CompileCommand: option com/oracle/Test.test bool MyBoolOption8 = true"
|
||||
}
|
||||
};
|
||||
|
||||
@ -88,38 +122,28 @@ public class CheckCompileCommandOption {
|
||||
"-XX:CompileCommand=option,Test::test,intx,MyIntxOption,-1",
|
||||
"-XX:CompileCommand=option,Test::test,uintx,MyUintxOption,1",
|
||||
"-XX:CompileCommand=option,Test::test,MyFlag",
|
||||
"-XX:CompileCommand=option,Test::test,double,MyDoubleOption,1.123",
|
||||
"-version"
|
||||
},
|
||||
{
|
||||
"-XX:CompileCommand=option,Test.test,double,MyDoubleOption,1.123",
|
||||
"-version"
|
||||
},
|
||||
{
|
||||
"-XX:CompileCommand=option,Test::test,bool,MyBoolOption,false,intx,MyIntxOption,-1,uintx,MyUintxOption,1,MyFlag,double,MyDoubleOption,1.123",
|
||||
"-XX:CompileCommand=option,Test::test,double,MyDoubleOption1,1.123",
|
||||
"-XX:CompileCommand=option,Test.test,double,MyDoubleOption2,1.123",
|
||||
"-XX:CompileCommand=option,Test::test,bool,MyBoolOptionX,false,intx,MyIntxOptionX,-1,uintx,MyUintxOptionX,1,MyFlagX,double,MyDoubleOptionX,1.123",
|
||||
"-version"
|
||||
}
|
||||
};
|
||||
|
||||
private static final String[][] TYPE_2_EXPECTED_OUTPUTS = {
|
||||
{
|
||||
"CompilerOracle: option Test.test const char* MyListOption = '_foo _bar'",
|
||||
"CompilerOracle: option Test.test const char* MyStrOption = '_foo'",
|
||||
"CompilerOracle: option Test.test bool MyBoolOption = false",
|
||||
"CompilerOracle: option Test.test intx MyIntxOption = -1",
|
||||
"CompilerOracle: option Test.test uintx MyUintxOption = 1",
|
||||
"CompilerOracle: option Test.test bool MyFlag = true",
|
||||
"CompilerOracle: option Test.test double MyDoubleOption = 1.123000"
|
||||
},
|
||||
{
|
||||
"CompilerOracle: option Test.test double MyDoubleOption = 1.123000"
|
||||
},
|
||||
{
|
||||
"CompilerOracle: option Test.test bool MyBoolOption = false",
|
||||
"CompilerOracle: option Test.test intx MyIntxOption = -1",
|
||||
"CompilerOracle: option Test.test uintx MyUintxOption = 1",
|
||||
"CompilerOracle: option Test.test bool MyFlag = true",
|
||||
"CompilerOracle: option Test.test double MyDoubleOption = 1.123000",
|
||||
"CompileCommand: option Test.test const char* MyListOption = '_foo _bar'",
|
||||
"CompileCommand: option Test.test const char* MyStrOption = '_foo'",
|
||||
"CompileCommand: option Test.test bool MyBoolOption = false",
|
||||
"CompileCommand: option Test.test intx MyIntxOption = -1",
|
||||
"CompileCommand: option Test.test uintx MyUintxOption = 1",
|
||||
"CompileCommand: option Test.test bool MyFlag = true",
|
||||
"CompileCommand: option Test.test double MyDoubleOption1 = 1.123000",
|
||||
"CompileCommand: option Test.test double MyDoubleOption2 = 1.123000",
|
||||
"CompileCommand: option Test.test bool MyBoolOptionX = false",
|
||||
"CompileCommand: option Test.test intx MyIntxOptionX = -1",
|
||||
"CompileCommand: option Test.test uintx MyUintxOptionX = 1",
|
||||
"CompileCommand: option Test.test bool MyFlagX = true",
|
||||
"CompileCommand: option Test.test double MyDoubleOptionX = 1.123000",
|
||||
}
|
||||
};
|
||||
|
||||
@ -172,7 +196,7 @@ public class CheckCompileCommandOption {
|
||||
out.shouldContain(expected_output);
|
||||
}
|
||||
|
||||
out.shouldNotContain("CompileCommand: unrecognized line");
|
||||
out.shouldNotContain("CompileCommand: An error occured during parsing");
|
||||
out.shouldHaveExitValue(0);
|
||||
}
|
||||
|
||||
@ -183,7 +207,7 @@ public class CheckCompileCommandOption {
|
||||
pb = ProcessTools.createJavaProcessBuilder(arguments);
|
||||
out = new OutputAnalyzer(pb.start());
|
||||
|
||||
out.shouldContain("CompileCommand: unrecognized line");
|
||||
out.shouldContain("CompileCommand: An error occured during parsing");
|
||||
out.shouldHaveExitValue(0);
|
||||
}
|
||||
|
||||
@ -212,5 +236,10 @@ public class CheckCompileCommandOption {
|
||||
for (String[] arguments: TYPE_2_INVALID_ARGUMENTS) {
|
||||
verifyInvalidOption(arguments);
|
||||
}
|
||||
|
||||
// Check if commands in command file are parsed correctly
|
||||
for (int i = 0; i < FILE_ARGUMENTS.length; i++) {
|
||||
verifyValidOption(FILE_ARGUMENTS[i], FILE_EXPECTED_OUTPUT[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
78
hotspot/test/compiler/oracle/TestCompileCommand.java
Normal file
78
hotspot/test/compiler/oracle/TestCompileCommand.java
Normal file
@ -0,0 +1,78 @@
|
||||
/*
|
||||
* 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.PrintWriter;
|
||||
import java.io.File;
|
||||
|
||||
import com.oracle.java.testlibrary.*;
|
||||
|
||||
/*
|
||||
* @test TestCompileCommand
|
||||
* @bug 8069389
|
||||
* @summary "Regression tests of -XX:CompileCommand"
|
||||
* @library /testlibrary
|
||||
* @run main TestCompileCommand
|
||||
*/
|
||||
|
||||
public class TestCompileCommand {
|
||||
|
||||
private static final String[][] ARGUMENTS = {
|
||||
{
|
||||
"-XX:CompileCommand=print,*01234567890123456789012345678901234567890123456789,*0123456789012345678901234567890123456789",
|
||||
"-version"
|
||||
}
|
||||
};
|
||||
|
||||
private static final String[][] OUTPUTS = {
|
||||
{
|
||||
"print *01234567890123456789012345678901234567890123456789.*0123456789012345678901234567890123456789"
|
||||
}
|
||||
};
|
||||
|
||||
private static void verifyValidOption(String[] arguments, String[] expected_outputs) throws Exception {
|
||||
ProcessBuilder pb;
|
||||
OutputAnalyzer out;
|
||||
|
||||
pb = ProcessTools.createJavaProcessBuilder(arguments);
|
||||
out = new OutputAnalyzer(pb.start());
|
||||
|
||||
for (String expected_output : expected_outputs) {
|
||||
out.shouldContain(expected_output);
|
||||
}
|
||||
|
||||
out.shouldNotContain("CompileCommand: An error occured during parsing");
|
||||
out.shouldHaveExitValue(0);
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
|
||||
if (ARGUMENTS.length != OUTPUTS.length) {
|
||||
throw new RuntimeException("Test is set up incorrectly: length of arguments and expected outputs for type (1) options does not match.");
|
||||
}
|
||||
|
||||
// Check if type (1) options are parsed correctly
|
||||
for (int i = 0; i < ARGUMENTS.length; i++) {
|
||||
verifyValidOption(ARGUMENTS[i], OUTPUTS[i]);
|
||||
}
|
||||
}
|
||||
}
|
12
hotspot/test/compiler/oracle/command1.txt
Normal file
12
hotspot/test/compiler/oracle/command1.txt
Normal file
@ -0,0 +1,12 @@
|
||||
option,com/oracle/Test.test,MyBoolOption1
|
||||
option,com/oracle/Test,test,MyBoolOption2
|
||||
option,com.oracle.Test::test,MyBoolOption3
|
||||
option,com/oracle/Test::test,MyBoolOption4
|
||||
option,com/oracle/Test.test,MyBoolOption5,MyBoolOption6
|
||||
option,com/oracle/Test,test,MyBoolOption7,MyBoolOption8
|
||||
option,com/oracle/Test.test(I),MyBoolOption9
|
||||
option,com/oracle/Test,test,(I),MyBoolOption10
|
||||
option,com.oracle.Test::test(I),MyBoolOption11
|
||||
option,com/oracle/Test::test(I),MyBoolOption12
|
||||
option,com/oracle/Test.test(I),MyBoolOption13,MyBoolOption14
|
||||
option,com/oracle/Test,test(I),MyBoolOption15,MyBoolOption16
|
7
hotspot/test/compiler/oracle/command2.txt
Normal file
7
hotspot/test/compiler/oracle/command2.txt
Normal file
@ -0,0 +1,7 @@
|
||||
option,Test::test,ccstrlist,MyListOption,_foo,_bar
|
||||
option,Test::test,ccstr,MyStrOption,_foo
|
||||
option,Test::test,bool,MyBoolOption,false
|
||||
option,Test::test,intx,MyIntxOption,-1
|
||||
option,Test::test,uintx,MyUintxOption,1
|
||||
option,Test::test,MyFlag
|
||||
option,Test::test,double,MyDoubleOption,1.123
|
@ -28,7 +28,6 @@ import com.oracle.java.testlibrary.*;
|
||||
* @bug 8038636
|
||||
* @library /testlibrary
|
||||
* @build Agent
|
||||
* @ignore 7076820
|
||||
* @run main ClassFileInstaller Agent
|
||||
* @run main Launcher
|
||||
* @run main/othervm -XX:-TieredCompilation -XX:-BackgroundCompilation -XX:-UseOnStackReplacement -XX:TypeProfileLevel=222 -XX:ReservedCodeCacheSize=3M Agent
|
||||
|
@ -28,7 +28,6 @@ import com.oracle.java.testlibrary.*;
|
||||
* @bug 8040237
|
||||
* @library /testlibrary
|
||||
* @build Agent Test A B
|
||||
* @ignore 7076820
|
||||
* @run main ClassFileInstaller Agent
|
||||
* @run main Launcher
|
||||
* @run main/othervm -XX:-TieredCompilation -XX:-BackgroundCompilation -XX:-UseOnStackReplacement -XX:TypeProfileLevel=222 -XX:ReservedCodeCacheSize=3M Agent
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2014, 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
|
||||
@ -119,13 +119,13 @@ public class TestRTMTotalCountIncrRate extends CommandLineOptionTest {
|
||||
return new String[] { getMethodWithLockName() };
|
||||
}
|
||||
|
||||
public void lock(booleab forceAbort) {
|
||||
public void lock(boolean forceAbort) {
|
||||
synchronized(monitor) {
|
||||
if (forceAbort) {
|
||||
// We're calling native method in order to force
|
||||
// abort. It's done by explicit xabort call emitted
|
||||
// in SharedRuntime::generate_native_wrapper.
|
||||
// If an actuall JNI call will be replaced by
|
||||
// If an actual JNI call will be replaced by
|
||||
// intrinsic - we'll be in trouble, since xabort
|
||||
// will be no longer called and test may fail.
|
||||
UNSAFE.addressSize();
|
||||
|
@ -34,7 +34,6 @@ import com.oracle.java.testlibrary.InfiniteLoop;
|
||||
/*
|
||||
* @test
|
||||
* @bug 8059624 8064669
|
||||
* @ignore 8066998
|
||||
* @library /testlibrary /../../test/lib
|
||||
* @build ForceNMethodSweepTest
|
||||
* @run main ClassFileInstaller sun.hotspot.WhiteBox
|
||||
@ -42,7 +41,7 @@ import com.oracle.java.testlibrary.InfiniteLoop;
|
||||
* @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions
|
||||
* -XX:-TieredCompilation -XX:+WhiteBoxAPI
|
||||
* -XX:CompileCommand=compileonly,SimpleTestCase$Helper::*
|
||||
* ForceNMethodSweepTest
|
||||
* -XX:-BackgroundCompilation ForceNMethodSweepTest
|
||||
* @summary testing of WB::forceNMethodSweep
|
||||
*/
|
||||
public class ForceNMethodSweepTest extends CompilerWhiteBoxTest {
|
||||
|
@ -41,6 +41,10 @@ public class CompressedClassSpaceSizeInJmapHeap {
|
||||
// Compressed Class Space is only available on 64-bit JVMs
|
||||
return;
|
||||
}
|
||||
if (!Platform.shouldSAAttach()) {
|
||||
System.out.println("SA attach not expected to work - test skipped.");
|
||||
return;
|
||||
}
|
||||
|
||||
String pid = Integer.toString(ProcessTools.getProcessId());
|
||||
|
||||
|
63
hotspot/test/runtime/Unsafe/AllocateInstance.java
Normal file
63
hotspot/test/runtime/Unsafe/AllocateInstance.java
Normal file
@ -0,0 +1,63 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @summary Verifies the behaviour of Unsafe.allocateInstance
|
||||
* @library /testlibrary
|
||||
* @run main AllocateInstance
|
||||
*/
|
||||
|
||||
import com.oracle.java.testlibrary.*;
|
||||
import sun.misc.Unsafe;
|
||||
import static com.oracle.java.testlibrary.Asserts.*;
|
||||
|
||||
public class AllocateInstance {
|
||||
public static void main(String args[]) throws Exception {
|
||||
Unsafe unsafe = Utils.getUnsafe();
|
||||
|
||||
// allocateInstance() should not result in a call to the constructor
|
||||
TestClass tc = (TestClass)unsafe.allocateInstance(TestClass.class);
|
||||
assertFalse(tc.calledConstructor);
|
||||
|
||||
// allocateInstance() on an abstract class should result in an InstantiationException
|
||||
try {
|
||||
AbstractClass ac = (AbstractClass)unsafe.allocateInstance(AbstractClass.class);
|
||||
throw new RuntimeException("Did not get expected InstantiationException");
|
||||
} catch (InstantiationException e) {
|
||||
// Expected
|
||||
}
|
||||
}
|
||||
|
||||
class TestClass {
|
||||
public boolean calledConstructor = false;
|
||||
|
||||
public TestClass() {
|
||||
calledConstructor = true;
|
||||
}
|
||||
}
|
||||
|
||||
abstract class AbstractClass {
|
||||
public AbstractClass() {}
|
||||
}
|
||||
}
|
66
hotspot/test/runtime/Unsafe/AllocateMemory.java
Normal file
66
hotspot/test/runtime/Unsafe/AllocateMemory.java
Normal file
@ -0,0 +1,66 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @summary Verifies behaviour of Unsafe.allocateMemory
|
||||
* @library /testlibrary
|
||||
* @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:MallocMaxTestWords=20m AllocateMemory
|
||||
*/
|
||||
|
||||
import com.oracle.java.testlibrary.*;
|
||||
import sun.misc.Unsafe;
|
||||
import static com.oracle.java.testlibrary.Asserts.*;
|
||||
|
||||
public class AllocateMemory {
|
||||
public static void main(String args[]) throws Exception {
|
||||
Unsafe unsafe = Utils.getUnsafe();
|
||||
|
||||
// Allocate a byte, write to the location and read back the value
|
||||
long address = unsafe.allocateMemory(1);
|
||||
assertNotEquals(address, 0L);
|
||||
|
||||
unsafe.putByte(address, Byte.MAX_VALUE);
|
||||
assertEquals(Byte.MAX_VALUE, unsafe.getByte(address));
|
||||
unsafe.freeMemory(address);
|
||||
|
||||
// Call to allocateMemory() with a negative value should result in an IllegalArgumentException
|
||||
try {
|
||||
address = unsafe.allocateMemory(-1);
|
||||
throw new RuntimeException("Did not get expected IllegalArgumentException");
|
||||
} catch (IllegalArgumentException e) {
|
||||
// Expected
|
||||
assertNotEquals(address, 0L);
|
||||
}
|
||||
|
||||
// allocateMemory() should throw an OutOfMemoryError when the underlying malloc fails,
|
||||
// we test this by limiting the malloc using -XX:MallocMaxTestWords
|
||||
try {
|
||||
address = unsafe.allocateMemory(20 * 1024 * 1024 * 8);
|
||||
} catch (OutOfMemoryError e) {
|
||||
// Expected
|
||||
return;
|
||||
}
|
||||
throw new RuntimeException("Did not get expected OutOfMemoryError");
|
||||
}
|
||||
}
|
56
hotspot/test/runtime/Unsafe/CopyMemory.java
Normal file
56
hotspot/test/runtime/Unsafe/CopyMemory.java
Normal file
@ -0,0 +1,56 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @summary Verifies behaviour of Unsafe.copyMemory
|
||||
* @library /testlibrary
|
||||
* @run main CopyMemory
|
||||
*/
|
||||
|
||||
import com.oracle.java.testlibrary.*;
|
||||
import sun.misc.Unsafe;
|
||||
import static com.oracle.java.testlibrary.Asserts.*;
|
||||
|
||||
public class CopyMemory {
|
||||
final static int LENGTH = 8;
|
||||
public static void main(String args[]) throws Exception {
|
||||
Unsafe unsafe = Utils.getUnsafe();
|
||||
long src = unsafe.allocateMemory(LENGTH);
|
||||
long dst = unsafe.allocateMemory(LENGTH);
|
||||
assertNotEquals(src, 0L);
|
||||
assertNotEquals(dst, 0L);
|
||||
|
||||
// call copyMemory() with different lengths and verify the contents of
|
||||
// the destination array
|
||||
for (int i = 0; i < LENGTH; i++) {
|
||||
unsafe.putByte(src + i, (byte)i);
|
||||
unsafe.copyMemory(src, dst, i);
|
||||
for (int j = 0; j < i; j++) {
|
||||
assertEquals(unsafe.getByte(src + j), unsafe.getByte(src + j));
|
||||
}
|
||||
}
|
||||
unsafe.freeMemory(src);
|
||||
unsafe.freeMemory(dst);
|
||||
}
|
||||
}
|
99
hotspot/test/runtime/Unsafe/DefineClass.java
Normal file
99
hotspot/test/runtime/Unsafe/DefineClass.java
Normal file
@ -0,0 +1,99 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @summary Verifies the behaviour of Unsafe.defineClass
|
||||
* @library /testlibrary
|
||||
* @run main DefineClass
|
||||
*/
|
||||
|
||||
import java.security.ProtectionDomain;
|
||||
import java.io.InputStream;
|
||||
import com.oracle.java.testlibrary.*;
|
||||
import sun.misc.Unsafe;
|
||||
import static com.oracle.java.testlibrary.Asserts.*;
|
||||
|
||||
public class DefineClass {
|
||||
public static void main(String args[]) throws Exception {
|
||||
Unsafe unsafe = Utils.getUnsafe();
|
||||
TestClassLoader classloader = new TestClassLoader();
|
||||
ProtectionDomain pd = new ProtectionDomain(null, null);
|
||||
|
||||
byte klassbuf[] = InMemoryJavaCompiler.compile("TestClass", "class TestClass { }");
|
||||
|
||||
// Invalid class data
|
||||
try {
|
||||
unsafe.defineClass(null, klassbuf, 4, klassbuf.length - 4, classloader, pd);
|
||||
throw new RuntimeException("defineClass did not throw expected ClassFormatError");
|
||||
} catch (ClassFormatError e) {
|
||||
// Expected
|
||||
}
|
||||
|
||||
// Negative offset
|
||||
try {
|
||||
unsafe.defineClass(null, klassbuf, -1, klassbuf.length, classloader, pd);
|
||||
throw new RuntimeException("defineClass did not throw expected IndexOutOfBoundsException");
|
||||
} catch (IndexOutOfBoundsException e) {
|
||||
// Expected
|
||||
}
|
||||
|
||||
// Negative length
|
||||
try {
|
||||
unsafe.defineClass(null, klassbuf, 0, -1, classloader, pd);
|
||||
throw new RuntimeException("defineClass did not throw expected IndexOutOfBoundsException");
|
||||
} catch (IndexOutOfBoundsException e) {
|
||||
// Expected
|
||||
}
|
||||
|
||||
// Offset greater than klassbuf.length
|
||||
try {
|
||||
unsafe.defineClass(null, klassbuf, klassbuf.length + 1, klassbuf.length, classloader, pd);
|
||||
throw new RuntimeException("defineClass did not throw expected IndexOutOfBoundsException");
|
||||
} catch (IndexOutOfBoundsException e) {
|
||||
// Expected
|
||||
}
|
||||
|
||||
// Length greater than klassbuf.length
|
||||
try {
|
||||
unsafe.defineClass(null, klassbuf, 0, klassbuf.length + 1, classloader, pd);
|
||||
throw new RuntimeException("defineClass did not throw expected IndexOutOfBoundsException");
|
||||
} catch (IndexOutOfBoundsException e) {
|
||||
// Expected
|
||||
}
|
||||
|
||||
Class klass = unsafe.defineClass(null, klassbuf, 0, klassbuf.length, classloader, pd);
|
||||
assertEquals(klass.getClassLoader(), classloader);
|
||||
assertEquals(klass.getProtectionDomain(), pd);
|
||||
}
|
||||
|
||||
private static class TestClassLoader extends ClassLoader {
|
||||
public TestClassLoader(ClassLoader parent) {
|
||||
super(parent);
|
||||
}
|
||||
|
||||
public TestClassLoader() {
|
||||
super();
|
||||
}
|
||||
}
|
||||
}
|
65
hotspot/test/runtime/Unsafe/FieldOffset.java
Normal file
65
hotspot/test/runtime/Unsafe/FieldOffset.java
Normal file
@ -0,0 +1,65 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @summary Verifies the behaviour of Unsafe.fieldOffset
|
||||
* @library /testlibrary
|
||||
* @run main FieldOffset
|
||||
*/
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import com.oracle.java.testlibrary.*;
|
||||
import sun.misc.Unsafe;
|
||||
import java.lang.reflect.*;
|
||||
import static com.oracle.java.testlibrary.Asserts.*;
|
||||
|
||||
public class FieldOffset {
|
||||
public static void main(String args[]) throws Exception {
|
||||
Unsafe unsafe = Utils.getUnsafe();
|
||||
Field fields[] = Test.class.getDeclaredFields();
|
||||
|
||||
for (int i = 0; i < fields.length; i++) {
|
||||
int offset = unsafe.fieldOffset(fields[i]);
|
||||
// Ensure we got a valid offset value back
|
||||
assertNotEquals(offset, unsafe.INVALID_FIELD_OFFSET);
|
||||
|
||||
// Make sure the field offset is unique
|
||||
for (int j = 0; j < i; j++) {
|
||||
assertNotEquals(offset, unsafe.fieldOffset(fields[j]));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class Test {
|
||||
boolean booleanField;
|
||||
byte byteField;
|
||||
char charField;
|
||||
double doubleField;
|
||||
float floatField;
|
||||
int intField;
|
||||
long longField;
|
||||
Object objectField;
|
||||
short shortField;
|
||||
}
|
||||
}
|
46
hotspot/test/runtime/Unsafe/GetField.java
Normal file
46
hotspot/test/runtime/Unsafe/GetField.java
Normal file
@ -0,0 +1,46 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @summary Verifies behaviour of Unsafe.getField
|
||||
* @library /testlibrary
|
||||
* @run main GetField
|
||||
*/
|
||||
|
||||
import com.oracle.java.testlibrary.*;
|
||||
import sun.misc.Unsafe;
|
||||
import java.lang.reflect.*;
|
||||
import static com.oracle.java.testlibrary.Asserts.*;
|
||||
|
||||
public class GetField {
|
||||
public static void main(String args[]) throws Exception {
|
||||
Unsafe unsafe = Utils.getUnsafe();
|
||||
// Unsafe.INVALID_FIELD_OFFSET is a static final int field,
|
||||
// make sure getField returns the correct field
|
||||
Field field = Unsafe.class.getField("INVALID_FIELD_OFFSET");
|
||||
assertNotEquals(field.getModifiers() & Modifier.FINAL, 0);
|
||||
assertNotEquals(field.getModifiers() & Modifier.STATIC, 0);
|
||||
assertEquals(field.getType(), int.class);
|
||||
}
|
||||
}
|
52
hotspot/test/runtime/Unsafe/GetPutAddress.java
Normal file
52
hotspot/test/runtime/Unsafe/GetPutAddress.java
Normal file
@ -0,0 +1,52 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* @test
|
||||
* Verify behaviour of Unsafe.get/putAddress and Unsafe.addressSize
|
||||
* @library /testlibrary
|
||||
* @run main GetPutAddress
|
||||
*/
|
||||
|
||||
import com.oracle.java.testlibrary.*;
|
||||
import sun.misc.Unsafe;
|
||||
import static com.oracle.java.testlibrary.Asserts.*;
|
||||
|
||||
public class GetPutAddress {
|
||||
public static void main(String args[]) throws Exception {
|
||||
Unsafe unsafe = Utils.getUnsafe();
|
||||
int addressSize = unsafe.addressSize();
|
||||
// Ensure the size returned from Unsafe.addressSize is correct
|
||||
assertEquals(unsafe.addressSize(), Platform.is32bit() ? 4 : 8);
|
||||
|
||||
// Write the address, read it back and make sure it's the same value
|
||||
long address = unsafe.allocateMemory(addressSize);
|
||||
unsafe.putAddress(address, address);
|
||||
long readAddress = unsafe.getAddress(address);
|
||||
if (addressSize == 4) {
|
||||
readAddress &= 0x00000000FFFFFFFFL;
|
||||
}
|
||||
assertEquals(address, readAddress);
|
||||
unsafe.freeMemory(address);
|
||||
}
|
||||
}
|
59
hotspot/test/runtime/Unsafe/GetPutBoolean.java
Normal file
59
hotspot/test/runtime/Unsafe/GetPutBoolean.java
Normal file
@ -0,0 +1,59 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @summary Verify behaviour of Unsafe.get/putBoolean
|
||||
* @library /testlibrary
|
||||
* @run main GetPutBoolean
|
||||
*/
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import com.oracle.java.testlibrary.*;
|
||||
import sun.misc.Unsafe;
|
||||
import static com.oracle.java.testlibrary.Asserts.*;
|
||||
|
||||
public class GetPutBoolean {
|
||||
public static void main(String args[]) throws Exception {
|
||||
Unsafe unsafe = Utils.getUnsafe();
|
||||
Test t = new Test();
|
||||
Field field = Test.class.getField("b1");
|
||||
|
||||
int offset = unsafe.fieldOffset(field);
|
||||
assertEquals(false, unsafe.getBoolean(t, offset));
|
||||
unsafe.putBoolean(t, offset, true);
|
||||
assertEquals(true, unsafe.getBoolean(t, offset));
|
||||
|
||||
boolean arrayBoolean[] = { true, false, false, true };
|
||||
int scale = unsafe.arrayIndexScale(arrayBoolean.getClass());
|
||||
offset = unsafe.arrayBaseOffset(arrayBoolean.getClass());
|
||||
for (int i = 0; i < arrayBoolean.length; i++) {
|
||||
assertEquals(unsafe.getBoolean(arrayBoolean, offset), arrayBoolean[i]);
|
||||
offset += scale;
|
||||
}
|
||||
}
|
||||
|
||||
static class Test {
|
||||
public boolean b1 = false;
|
||||
}
|
||||
}
|
64
hotspot/test/runtime/Unsafe/GetPutByte.java
Normal file
64
hotspot/test/runtime/Unsafe/GetPutByte.java
Normal file
@ -0,0 +1,64 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @summary Verify behaviour of Unsafe.get/putByte
|
||||
* @library /testlibrary
|
||||
* @run main GetPutByte
|
||||
*/
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import com.oracle.java.testlibrary.*;
|
||||
import sun.misc.Unsafe;
|
||||
import static com.oracle.java.testlibrary.Asserts.*;
|
||||
|
||||
public class GetPutByte {
|
||||
public static void main(String args[]) throws Exception {
|
||||
Unsafe unsafe = Utils.getUnsafe();
|
||||
Test t = new Test();
|
||||
Field field = Test.class.getField("b");
|
||||
|
||||
int offset = unsafe.fieldOffset(field);
|
||||
assertEquals((byte)0, unsafe.getByte(t, offset));
|
||||
unsafe.putByte(t, offset, (byte)1);
|
||||
assertEquals((byte)1, unsafe.getByte(t, offset));
|
||||
|
||||
long address = unsafe.allocateMemory(8);
|
||||
unsafe.putByte(address, (byte)2);
|
||||
assertEquals((byte)2, unsafe.getByte(address));
|
||||
unsafe.freeMemory(address);
|
||||
|
||||
byte arrayByte[] = { -1, 0, 1, 2 };
|
||||
int scale = unsafe.arrayIndexScale(arrayByte.getClass());
|
||||
offset = unsafe.arrayBaseOffset(arrayByte.getClass());
|
||||
for (int i = 0; i < arrayByte.length; i++) {
|
||||
assertEquals(unsafe.getByte(arrayByte, offset), arrayByte[i]);
|
||||
offset += scale;
|
||||
}
|
||||
}
|
||||
|
||||
static class Test {
|
||||
public byte b = 0;
|
||||
}
|
||||
}
|
64
hotspot/test/runtime/Unsafe/GetPutChar.java
Normal file
64
hotspot/test/runtime/Unsafe/GetPutChar.java
Normal file
@ -0,0 +1,64 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @summary Verify behaviour of Unsafe.get/putChar
|
||||
* @library /testlibrary
|
||||
* @run main GetPutChar
|
||||
*/
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import com.oracle.java.testlibrary.*;
|
||||
import sun.misc.Unsafe;
|
||||
import static com.oracle.java.testlibrary.Asserts.*;
|
||||
|
||||
public class GetPutChar {
|
||||
public static void main(String args[]) throws Exception {
|
||||
Unsafe unsafe = Utils.getUnsafe();
|
||||
Test t = new Test();
|
||||
Field field = Test.class.getField("c");
|
||||
|
||||
int offset = unsafe.fieldOffset(field);
|
||||
assertEquals('\u0000', unsafe.getChar(t, offset));
|
||||
unsafe.putChar(t, offset, '\u0001');
|
||||
assertEquals('\u0001', unsafe.getChar(t, offset));
|
||||
|
||||
long address = unsafe.allocateMemory(8);
|
||||
unsafe.putChar(address, '\u0002');
|
||||
assertEquals('\u0002', unsafe.getChar(address));
|
||||
unsafe.freeMemory(address);
|
||||
|
||||
char arrayChar[] = { '\uabcd', '\u00ff', '\uff00', };
|
||||
int scale = unsafe.arrayIndexScale(arrayChar.getClass());
|
||||
offset = unsafe.arrayBaseOffset(arrayChar.getClass());
|
||||
for (int i = 0; i < arrayChar.length; i++) {
|
||||
assertEquals(unsafe.getChar(arrayChar, offset), arrayChar[i]);
|
||||
offset += scale;
|
||||
}
|
||||
}
|
||||
|
||||
static class Test {
|
||||
public char c = '\u0000';
|
||||
}
|
||||
}
|
64
hotspot/test/runtime/Unsafe/GetPutDouble.java
Normal file
64
hotspot/test/runtime/Unsafe/GetPutDouble.java
Normal file
@ -0,0 +1,64 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @summary Verify behaviour of Unsafe.get/putDouble
|
||||
* @library /testlibrary
|
||||
* @run main GetPutDouble
|
||||
*/
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import com.oracle.java.testlibrary.*;
|
||||
import sun.misc.Unsafe;
|
||||
import static com.oracle.java.testlibrary.Asserts.*;
|
||||
|
||||
public class GetPutDouble {
|
||||
public static void main(String args[]) throws Exception {
|
||||
Unsafe unsafe = Utils.getUnsafe();
|
||||
Test t = new Test();
|
||||
Field field = Test.class.getField("d");
|
||||
|
||||
int offset = unsafe.fieldOffset(field);
|
||||
assertEquals(-1.0, unsafe.getDouble(t, offset));
|
||||
unsafe.putDouble(t, offset, 0.0);
|
||||
assertEquals(0.0, unsafe.getDouble(t, offset));
|
||||
|
||||
long address = unsafe.allocateMemory(8);
|
||||
unsafe.putDouble(address, 1.0);
|
||||
assertEquals(1.0, unsafe.getDouble(address));
|
||||
unsafe.freeMemory(address);
|
||||
|
||||
double arrayDouble[] = { -1.0, 0.0, 1.0, 2.0 };
|
||||
int scale = unsafe.arrayIndexScale(arrayDouble.getClass());
|
||||
offset = unsafe.arrayBaseOffset(arrayDouble.getClass());
|
||||
for (int i = 0; i < arrayDouble.length; i++) {
|
||||
assertEquals(unsafe.getDouble(arrayDouble, offset), arrayDouble[i]);
|
||||
offset += scale;
|
||||
}
|
||||
}
|
||||
|
||||
static class Test {
|
||||
public double d = -1.0;
|
||||
}
|
||||
}
|
64
hotspot/test/runtime/Unsafe/GetPutFloat.java
Normal file
64
hotspot/test/runtime/Unsafe/GetPutFloat.java
Normal file
@ -0,0 +1,64 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @summary Verify behaviour of Unsafe.get/putFloat
|
||||
* @library /testlibrary
|
||||
* @run main GetPutFloat
|
||||
*/
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import com.oracle.java.testlibrary.*;
|
||||
import sun.misc.Unsafe;
|
||||
import static com.oracle.java.testlibrary.Asserts.*;
|
||||
|
||||
public class GetPutFloat {
|
||||
public static void main(String args[]) throws Exception {
|
||||
Unsafe unsafe = Utils.getUnsafe();
|
||||
Test t = new Test();
|
||||
Field field = Test.class.getField("f");
|
||||
|
||||
int offset = unsafe.fieldOffset(field);
|
||||
assertEquals(-1.0f, unsafe.getFloat(t, offset));
|
||||
unsafe.putFloat(t, offset, 0.0f);
|
||||
assertEquals(0.0f, unsafe.getFloat(t, offset));
|
||||
|
||||
long address = unsafe.allocateMemory(8);
|
||||
unsafe.putFloat(address, 1.0f);
|
||||
assertEquals(1.0f, unsafe.getFloat(address));
|
||||
unsafe.freeMemory(address);
|
||||
|
||||
float arrayFloat[] = { -1.0f, 0.0f, 1.0f, 2.0f };
|
||||
int scale = unsafe.arrayIndexScale(arrayFloat.getClass());
|
||||
offset = unsafe.arrayBaseOffset(arrayFloat.getClass());
|
||||
for (int i = 0; i < arrayFloat.length; i++) {
|
||||
assertEquals(unsafe.getFloat(arrayFloat, offset), arrayFloat[i]);
|
||||
offset += scale;
|
||||
}
|
||||
}
|
||||
|
||||
static class Test {
|
||||
public float f = -1.0f;
|
||||
}
|
||||
}
|
63
hotspot/test/runtime/Unsafe/GetPutInt.java
Normal file
63
hotspot/test/runtime/Unsafe/GetPutInt.java
Normal file
@ -0,0 +1,63 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @library /testlibrary
|
||||
* @run main GetPutInt
|
||||
*/
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import com.oracle.java.testlibrary.*;
|
||||
import sun.misc.Unsafe;
|
||||
import static com.oracle.java.testlibrary.Asserts.*;
|
||||
|
||||
public class GetPutInt {
|
||||
public static void main(String args[]) throws Exception {
|
||||
Unsafe unsafe = Utils.getUnsafe();
|
||||
Test t = new Test();
|
||||
Field field = Test.class.getField("i");
|
||||
|
||||
int offset = unsafe.fieldOffset(field);
|
||||
assertEquals(-1, unsafe.getInt(t, offset));
|
||||
unsafe.putInt(t, offset, 0);
|
||||
assertEquals(0, unsafe.getInt(t, offset));
|
||||
|
||||
long address = unsafe.allocateMemory(8);
|
||||
unsafe.putInt(address, 1);
|
||||
assertEquals(1, unsafe.getInt(address));
|
||||
unsafe.freeMemory(address);
|
||||
|
||||
int arrayInt[] = { -1, 0, 1, 2 };
|
||||
int scale = unsafe.arrayIndexScale(arrayInt.getClass());
|
||||
offset = unsafe.arrayBaseOffset(arrayInt.getClass());
|
||||
for (int i = 0; i < arrayInt.length; i++) {
|
||||
assertEquals(unsafe.getInt(arrayInt, offset), arrayInt[i]);
|
||||
offset += scale;
|
||||
}
|
||||
}
|
||||
|
||||
static class Test {
|
||||
public int i = -1;
|
||||
}
|
||||
}
|
64
hotspot/test/runtime/Unsafe/GetPutLong.java
Normal file
64
hotspot/test/runtime/Unsafe/GetPutLong.java
Normal file
@ -0,0 +1,64 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @summary Verify behaviour of Unsafe.get/putLong
|
||||
* @library /testlibrary
|
||||
* @run main GetPutLong
|
||||
*/
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import com.oracle.java.testlibrary.*;
|
||||
import sun.misc.Unsafe;
|
||||
import static com.oracle.java.testlibrary.Asserts.*;
|
||||
|
||||
public class GetPutLong {
|
||||
public static void main(String args[]) throws Exception {
|
||||
Unsafe unsafe = Utils.getUnsafe();
|
||||
Test t = new Test();
|
||||
Field field = Test.class.getField("l");
|
||||
|
||||
int offset = unsafe.fieldOffset(field);
|
||||
assertEquals(-1L, unsafe.getLong(t, offset));
|
||||
unsafe.putLong(t, offset, 0L);
|
||||
assertEquals(0L, unsafe.getLong(t, offset));
|
||||
|
||||
long address = unsafe.allocateMemory(8);
|
||||
unsafe.putLong(address, 1L);
|
||||
assertEquals(1L, unsafe.getLong(address));
|
||||
unsafe.freeMemory(address);
|
||||
|
||||
long arrayLong[] = { -1, 0, 1, 2 };
|
||||
int scale = unsafe.arrayIndexScale(arrayLong.getClass());
|
||||
offset = unsafe.arrayBaseOffset(arrayLong.getClass());
|
||||
for (int i = 0; i < arrayLong.length; i++) {
|
||||
assertEquals(unsafe.getLong(arrayLong, offset), arrayLong[i]);
|
||||
offset += scale;
|
||||
}
|
||||
}
|
||||
|
||||
static class Test {
|
||||
public long l = -1L;
|
||||
}
|
||||
}
|
61
hotspot/test/runtime/Unsafe/GetPutObject.java
Normal file
61
hotspot/test/runtime/Unsafe/GetPutObject.java
Normal file
@ -0,0 +1,61 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @summary Verify behaviour of Unsafe.get/putObject
|
||||
* @library /testlibrary
|
||||
* @run main GetPutObject
|
||||
*/
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import com.oracle.java.testlibrary.*;
|
||||
import sun.misc.Unsafe;
|
||||
import static com.oracle.java.testlibrary.Asserts.*;
|
||||
|
||||
public class GetPutObject {
|
||||
public static void main(String args[]) throws Exception {
|
||||
Unsafe unsafe = Utils.getUnsafe();
|
||||
Test t = new Test();
|
||||
Object o = new Object();
|
||||
Field field = Test.class.getField("o");
|
||||
|
||||
int offset = unsafe.fieldOffset(field);
|
||||
assertEquals(t.o, unsafe.getObject(t, offset));
|
||||
|
||||
unsafe.putObject(t, offset, o);
|
||||
assertEquals(o, unsafe.getObject(t, offset));
|
||||
|
||||
Object arrayObject[] = { unsafe, null, new Object() };
|
||||
int scale = unsafe.arrayIndexScale(arrayObject.getClass());
|
||||
offset = unsafe.arrayBaseOffset(arrayObject.getClass());
|
||||
for (int i = 0; i < arrayObject.length; i++) {
|
||||
assertEquals(unsafe.getObject(arrayObject, offset), arrayObject[i]);
|
||||
offset += scale;
|
||||
}
|
||||
}
|
||||
|
||||
static class Test {
|
||||
public Object o = new Object();
|
||||
}
|
||||
}
|
64
hotspot/test/runtime/Unsafe/GetPutShort.java
Normal file
64
hotspot/test/runtime/Unsafe/GetPutShort.java
Normal file
@ -0,0 +1,64 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @summary Verify behaviour of Unsafe.get/putShort
|
||||
* @library /testlibrary
|
||||
* @run main GetPutShort
|
||||
*/
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import com.oracle.java.testlibrary.*;
|
||||
import sun.misc.Unsafe;
|
||||
import static com.oracle.java.testlibrary.Asserts.*;
|
||||
|
||||
public class GetPutShort {
|
||||
public static void main(String args[]) throws Exception {
|
||||
Unsafe unsafe = Utils.getUnsafe();
|
||||
Test t = new Test();
|
||||
Field field = Test.class.getField("s");
|
||||
|
||||
int offset = unsafe.fieldOffset(field);
|
||||
assertEquals((short)-1, unsafe.getShort(t, offset));
|
||||
unsafe.putShort(t, offset, (short)0);
|
||||
assertEquals((short)0, unsafe.getShort(t, offset));
|
||||
|
||||
long address = unsafe.allocateMemory(8);
|
||||
unsafe.putShort(address, (short)1);
|
||||
assertEquals((short)1, unsafe.getShort(address));
|
||||
unsafe.freeMemory(address);
|
||||
|
||||
short arrayShort[] = { -1, 0, 1, 2 };
|
||||
int scale = unsafe.arrayIndexScale(arrayShort.getClass());
|
||||
offset = unsafe.arrayBaseOffset(arrayShort.getClass());
|
||||
for (int i = 0; i < arrayShort.length; i++) {
|
||||
assertEquals(unsafe.getShort(arrayShort, offset), arrayShort[i]);
|
||||
offset += scale;
|
||||
}
|
||||
}
|
||||
|
||||
static class Test {
|
||||
public short s = -1;
|
||||
}
|
||||
}
|
44
hotspot/test/runtime/Unsafe/GetUnsafe.java
Normal file
44
hotspot/test/runtime/Unsafe/GetUnsafe.java
Normal file
@ -0,0 +1,44 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @summary Verifies that getUnsafe() actually throws SecurityException when unsafeAccess is prohibited.
|
||||
* @library /testlibrary
|
||||
* @run main GetUnsafe
|
||||
*/
|
||||
|
||||
import sun.misc.Unsafe;
|
||||
import static com.oracle.java.testlibrary.Asserts.*;
|
||||
|
||||
public class GetUnsafe {
|
||||
public static void main(String args[]) throws Exception {
|
||||
try {
|
||||
Unsafe unsafe = Unsafe.getUnsafe();
|
||||
} catch (SecurityException e) {
|
||||
// Expected
|
||||
return;
|
||||
}
|
||||
throw new RuntimeException("Did not get expected SecurityException");
|
||||
}
|
||||
}
|
48
hotspot/test/runtime/Unsafe/PageSize.java
Normal file
48
hotspot/test/runtime/Unsafe/PageSize.java
Normal file
@ -0,0 +1,48 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @summary Make sure pageSize() returns a value that is a power of two
|
||||
* @library /testlibrary
|
||||
* @run main PageSize
|
||||
*/
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import com.oracle.java.testlibrary.*;
|
||||
import sun.misc.Unsafe;
|
||||
import static com.oracle.java.testlibrary.Asserts.*;
|
||||
|
||||
public class PageSize {
|
||||
public static void main(String args[]) throws Exception {
|
||||
Unsafe unsafe = Utils.getUnsafe();
|
||||
int pageSize = unsafe.pageSize();
|
||||
|
||||
for (int n = 1; n != 0; n <<= 1) {
|
||||
if (pageSize == n) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
throw new RuntimeException("Expected pagesize to be a power of two, actual pagesize:" + pageSize);
|
||||
}
|
||||
}
|
44
hotspot/test/runtime/Unsafe/SetMemory.java
Normal file
44
hotspot/test/runtime/Unsafe/SetMemory.java
Normal file
@ -0,0 +1,44 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @summary Verifies that setMemory works correctly
|
||||
* @library /testlibrary
|
||||
* @run main SetMemory
|
||||
*/
|
||||
|
||||
import com.oracle.java.testlibrary.*;
|
||||
import sun.misc.Unsafe;
|
||||
import static com.oracle.java.testlibrary.Asserts.*;
|
||||
|
||||
public class SetMemory {
|
||||
public static void main(String args[]) throws Exception {
|
||||
Unsafe unsafe = Utils.getUnsafe();
|
||||
long address = unsafe.allocateMemory(1);
|
||||
assertNotEquals(address, 0L);
|
||||
unsafe.setMemory(address, 1, (byte)17);
|
||||
assertEquals((byte)17, unsafe.getByte(address));
|
||||
unsafe.freeMemory(address);
|
||||
}
|
||||
}
|
49
hotspot/test/runtime/Unsafe/ThrowException.java
Normal file
49
hotspot/test/runtime/Unsafe/ThrowException.java
Normal file
@ -0,0 +1,49 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @summary Verify that throwException() can throw an exception
|
||||
* @library /testlibrary
|
||||
* @run main ThrowException
|
||||
*/
|
||||
|
||||
import com.oracle.java.testlibrary.*;
|
||||
import sun.misc.Unsafe;
|
||||
import static com.oracle.java.testlibrary.Asserts.*;
|
||||
|
||||
public class ThrowException {
|
||||
public static void main(String args[]) throws Exception {
|
||||
Unsafe unsafe = Utils.getUnsafe();
|
||||
try {
|
||||
unsafe.throwException(new TestException());
|
||||
} catch (Throwable t) {
|
||||
if (t instanceof TestException) {
|
||||
return;
|
||||
}
|
||||
throw t;
|
||||
}
|
||||
throw new RuntimeException("Did not throw expected TestException");
|
||||
}
|
||||
static class TestException extends Exception {}
|
||||
}
|
@ -0,0 +1,138 @@
|
||||
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @bug 8008678
|
||||
* @summary JSR 292: constant pool reconstitution must support pseudo strings
|
||||
* @library /testlibrary
|
||||
* @compile -XDignore.symbol.file TestLambdaFormRetransformation.java
|
||||
* @run main TestLambdaFormRetransformation
|
||||
*/
|
||||
|
||||
import java.io.IOException;
|
||||
import java.lang.instrument.ClassFileTransformer;
|
||||
import java.lang.instrument.IllegalClassFormatException;
|
||||
import java.lang.instrument.Instrumentation;
|
||||
import java.lang.instrument.UnmodifiableClassException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.security.ProtectionDomain;
|
||||
import java.util.Arrays;
|
||||
|
||||
import com.oracle.java.testlibrary.ExitCode;
|
||||
import com.oracle.java.testlibrary.OutputAnalyzer;
|
||||
import com.oracle.java.testlibrary.ProcessTools;
|
||||
|
||||
public class TestLambdaFormRetransformation {
|
||||
private static String MANIFEST = String.format("Manifest-Version: 1.0\n" +
|
||||
"Premain-Class: %s\n" +
|
||||
"Can-Retransform-Classes: true\n",
|
||||
Agent.class.getName());
|
||||
|
||||
private static String CP = System.getProperty("test.classes");
|
||||
|
||||
public static void main(String args[]) throws Throwable {
|
||||
Path agent = TestLambdaFormRetransformation.buildAgent();
|
||||
OutputAnalyzer oa = ProcessTools.executeTestJvm("-javaagent:" +
|
||||
agent.toAbsolutePath().toString(), "-version");
|
||||
oa.shouldHaveExitValue(ExitCode.OK.value);
|
||||
}
|
||||
|
||||
private static Path buildAgent() throws IOException {
|
||||
Path manifest = TestLambdaFormRetransformation.createManifest();
|
||||
Path jar = Files.createTempFile(Paths.get("."), null, ".jar");
|
||||
|
||||
String[] args = new String[] {
|
||||
"-cfm",
|
||||
jar.toAbsolutePath().toString(),
|
||||
manifest.toAbsolutePath().toString(),
|
||||
"-C",
|
||||
TestLambdaFormRetransformation.CP,
|
||||
Agent.class.getName() + ".class"
|
||||
};
|
||||
|
||||
sun.tools.jar.Main jarTool = new sun.tools.jar.Main(System.out, System.err, "jar");
|
||||
|
||||
if (!jarTool.run(args)) {
|
||||
throw new Error("jar failed: args=" + Arrays.toString(args));
|
||||
}
|
||||
return jar;
|
||||
}
|
||||
|
||||
private static Path createManifest() throws IOException {
|
||||
Path manifest = Files.createTempFile(Paths.get("."), null, ".mf");
|
||||
byte[] manifestBytes = TestLambdaFormRetransformation.MANIFEST.getBytes();
|
||||
Files.write(manifest, manifestBytes);
|
||||
return manifest;
|
||||
}
|
||||
}
|
||||
|
||||
class Agent implements ClassFileTransformer {
|
||||
private static Runnable lambda = () -> {
|
||||
System.out.println("I'll crash you!");
|
||||
};
|
||||
|
||||
public static void premain(String args, Instrumentation instrumentation) {
|
||||
if (!instrumentation.isRetransformClassesSupported()) {
|
||||
System.out.println("Class retransformation is not supported.");
|
||||
return;
|
||||
}
|
||||
System.out.println("Calling lambda to ensure that lambda forms were created");
|
||||
|
||||
Agent.lambda.run();
|
||||
|
||||
System.out.println("Registering class file transformer");
|
||||
|
||||
instrumentation.addTransformer(new Agent());
|
||||
|
||||
for (Class c : instrumentation.getAllLoadedClasses()) {
|
||||
if (c.getName().contains("LambdaForm") &&
|
||||
instrumentation.isModifiableClass(c)) {
|
||||
System.out.format("We've found a modifiable lambda form: %s%n", c.getName());
|
||||
try {
|
||||
instrumentation.retransformClasses(c);
|
||||
} catch (UnmodifiableClassException e) {
|
||||
throw new AssertionError("Modification of modifiable class " +
|
||||
"caused UnmodifiableClassException", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String args[]) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] transform(ClassLoader loader,
|
||||
String className,
|
||||
Class<?> classBeingRedefined,
|
||||
ProtectionDomain protectionDomain,
|
||||
byte[] classfileBuffer
|
||||
) throws IllegalClassFormatException {
|
||||
System.out.println("Transforming " + className);
|
||||
return classfileBuffer.clone();
|
||||
}
|
||||
}
|
@ -291,3 +291,4 @@ a12d347f84176200593999f4da91ae2bb86865b2 jdk9-b39
|
||||
74eaf7ad986576c792df4dbff05eed63e5727695 jdk9-b46
|
||||
e391de88e69b59d7c618387e3cf91032f6991ce9 jdk9-b47
|
||||
833051855168a973780fafeb6fc59e7370bcf400 jdk9-b48
|
||||
786058752e0ac3e48d7aef79e0885d29d6a2a7eb jdk9-b49
|
||||
|
@ -0,0 +1,585 @@
|
||||
/*
|
||||
* Copyright (c) 1999, 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.
|
||||
*/
|
||||
|
||||
package javax.xml.datatype.ptests;
|
||||
|
||||
import static javax.xml.datatype.DatatypeConstants.DAYS;
|
||||
import static javax.xml.datatype.DatatypeConstants.HOURS;
|
||||
import static javax.xml.datatype.DatatypeConstants.MINUTES;
|
||||
import static javax.xml.datatype.DatatypeConstants.MONTHS;
|
||||
import static javax.xml.datatype.DatatypeConstants.SECONDS;
|
||||
import static javax.xml.datatype.DatatypeConstants.YEARS;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
import static org.testng.Assert.assertFalse;
|
||||
import static org.testng.Assert.assertTrue;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.math.BigInteger;
|
||||
import java.util.Calendar;
|
||||
import java.util.function.Function;
|
||||
|
||||
import javax.xml.datatype.DatatypeConfigurationException;
|
||||
import javax.xml.datatype.DatatypeConstants;
|
||||
import javax.xml.datatype.DatatypeFactory;
|
||||
import javax.xml.datatype.Duration;
|
||||
import javax.xml.namespace.QName;
|
||||
|
||||
import jaxp.library.JAXPBaseTest;
|
||||
|
||||
import org.testng.Assert;
|
||||
import org.testng.annotations.BeforeClass;
|
||||
import org.testng.annotations.DataProvider;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
/*
|
||||
* @summary Class containing the test cases for Duration.
|
||||
*/
|
||||
public class DurationTest extends JAXPBaseTest {
|
||||
|
||||
private DatatypeFactory datatypeFactory;
|
||||
|
||||
/*
|
||||
* Setup.
|
||||
*/
|
||||
@BeforeClass
|
||||
public void setup() throws DatatypeConfigurationException {
|
||||
datatypeFactory = DatatypeFactory.newInstance();
|
||||
}
|
||||
|
||||
@DataProvider(name = "legal-number-duration")
|
||||
public Object[][] getLegalNumberDuration() {
|
||||
return new Object[][] {
|
||||
// is positive, year, month, day, hour, minute, second
|
||||
{ true, 1, 1, 1, 1, 1, 1 },
|
||||
{ false, 1, 1, 1, 1, 1, 1 },
|
||||
{ true, 1, 0, 0, 0, 0, 0 },
|
||||
{ false, 1, 0, 0, 0, 0, 0 }
|
||||
};
|
||||
}
|
||||
|
||||
/*
|
||||
* Test for constructor Duration(boolean isPositive,int years,int months,
|
||||
* int days,int hours,int minutes,int seconds).
|
||||
*/
|
||||
@Test(dataProvider = "legal-number-duration")
|
||||
public void checkNumberDurationPos(boolean isPositive, int years, int months, int days, int hours, int minutes, int seconds) {
|
||||
datatypeFactory.newDuration(isPositive, years, months, days, hours, minutes, seconds);
|
||||
}
|
||||
|
||||
@DataProvider(name = "illegal-number-duration")
|
||||
public Object[][] getIllegalNumberDuration() {
|
||||
return new Object[][] {
|
||||
// is positive, year, month, day, hour, minute, second
|
||||
{ true, 1, 1, -1, 1, 1, 1 },
|
||||
{ false, 1, 1, -1, 1, 1, 1 },
|
||||
{ true, undef, undef, undef, undef, undef, undef },
|
||||
{ false, undef, undef, undef, undef, undef, undef }
|
||||
};
|
||||
}
|
||||
|
||||
/*
|
||||
* Test for constructor Duration(boolean isPositive,int years,int months,
|
||||
* int days,int hours,int minutes,int seconds), if any of the fields is
|
||||
* negative should throw IllegalArgumentException.
|
||||
*/
|
||||
@Test(expectedExceptions = IllegalArgumentException.class, dataProvider = "illegal-number-duration")
|
||||
public void checkDurationNumberNeg(boolean isPositive, int years, int months, int days, int hours, int minutes, int seconds) {
|
||||
datatypeFactory.newDuration(isPositive, years, months, days, hours, minutes, seconds);
|
||||
}
|
||||
|
||||
@DataProvider(name = "legal-bigint-duration")
|
||||
public Object[][] getLegalBigIntegerDuration() {
|
||||
return new Object[][] {
|
||||
// is positive, year, month, day, hour, minute, second
|
||||
{ true, zero, zero, zero, zero, zero, new BigDecimal(zero) },
|
||||
{ false, zero, zero, zero, zero, zero, new BigDecimal(zero) },
|
||||
{ true, one, one, one, one, one, new BigDecimal(one) },
|
||||
{ false, one, one, one, one, one, new BigDecimal(one) },
|
||||
{ true, null, null, null, null, null, new BigDecimal(one) },
|
||||
{ false, null, null, null, null, null, new BigDecimal(one) } };
|
||||
}
|
||||
|
||||
/*
|
||||
* Test for constructor Duration(boolean isPositive,BigInteger
|
||||
* years,BigInteger months, BigInteger days,BigInteger hours,BigInteger
|
||||
* minutes,BigDecimal seconds).
|
||||
*/
|
||||
@Test(dataProvider = "legal-bigint-duration")
|
||||
public void checkBigIntegerDurationPos(boolean isPositive, BigInteger years, BigInteger months, BigInteger days, BigInteger hours, BigInteger minutes,
|
||||
BigDecimal seconds) {
|
||||
datatypeFactory.newDuration(isPositive, years, months, days, hours, minutes, seconds);
|
||||
}
|
||||
|
||||
@DataProvider(name = "illegal-bigint-duration")
|
||||
public Object[][] getIllegalBigIntegerDuration() {
|
||||
return new Object[][] {
|
||||
// is positive, year, month, day, hour, minute, second
|
||||
{ true, null, null, null, null, null, null },
|
||||
{ false, null, null, null, null, null, null }
|
||||
};
|
||||
}
|
||||
|
||||
/*
|
||||
* Test for constructor Duration(boolean isPositive,BigInteger
|
||||
* years,BigInteger months, BigInteger days,BigInteger hours,BigInteger
|
||||
* minutes,BigDecimal seconds), if all the fields are null should throw
|
||||
* IllegalArgumentException.
|
||||
*/
|
||||
@Test(expectedExceptions = IllegalArgumentException.class, dataProvider = "illegal-bigint-duration")
|
||||
public void checkBigIntegerDurationNeg(boolean isPositive, BigInteger years, BigInteger months, BigInteger days, BigInteger hours, BigInteger minutes,
|
||||
BigDecimal seconds) {
|
||||
datatypeFactory.newDuration(isPositive, years, months, days, hours, minutes, seconds);
|
||||
}
|
||||
|
||||
@DataProvider(name = "legal-millisec-duration")
|
||||
public Object[][] getLegalMilliSecondDuration() {
|
||||
return new Object[][] { { 1000000 }, { 0 }, { Long.MAX_VALUE }, { Long.MIN_VALUE }
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
/*
|
||||
* Test for constructor Duration(long durationInMilliSeconds)
|
||||
*/
|
||||
@Test(dataProvider = "legal-millisec-duration")
|
||||
public void checkMilliSecondDuration(long millisec) {
|
||||
datatypeFactory.newDuration(millisec);
|
||||
}
|
||||
|
||||
@DataProvider(name = "legal-lexical-duration")
|
||||
public Object[][] getLegalLexicalDuration() {
|
||||
return new Object[][] { { "P1Y1M1DT1H1M1S" }, { "-P1Y1M1DT1H1M1S" } };
|
||||
}
|
||||
|
||||
/*
|
||||
* Test for constructor Duration(java.lang.String lexicalRepresentation)
|
||||
*/
|
||||
@Test(dataProvider = "legal-lexical-duration")
|
||||
public void checkLexicalDurationPos(String lexRepresentation) {
|
||||
datatypeFactory.newDuration(lexRepresentation);
|
||||
}
|
||||
|
||||
@DataProvider(name = "illegal-lexical-duration")
|
||||
public Object[][] getIllegalLexicalDuration() {
|
||||
return new Object[][] {
|
||||
{ null },
|
||||
{ "P1Y1M1DT1H1M1S " },
|
||||
{ " P1Y1M1DT1H1M1S" },
|
||||
{ "X1Y1M1DT1H1M1S" },
|
||||
{ "" },
|
||||
{ "P1Y2MT" } // The designator 'T' shall be absent if all of the time items are absent in "PnYnMnDTnHnMnS"
|
||||
};
|
||||
}
|
||||
|
||||
/*
|
||||
* Test for constructor Duration(java.lang.String lexicalRepresentation),
|
||||
* null should throw NullPointerException, invalid lex should throw
|
||||
* IllegalArgumentException
|
||||
*/
|
||||
@Test(expectedExceptions = { NullPointerException.class, IllegalArgumentException.class }, dataProvider = "illegal-lexical-duration")
|
||||
public void checkLexicalDurationNeg(String lexRepresentation) {
|
||||
datatypeFactory.newDuration(lexRepresentation);
|
||||
}
|
||||
|
||||
@DataProvider(name = "equal-duration")
|
||||
public Object[][] getEqualDurations() {
|
||||
return new Object[][] { { "P1Y1M1DT1H1M1S", "P1Y1M1DT1H1M1S" } };
|
||||
}
|
||||
|
||||
/*
|
||||
* Test for compare() both durations valid and equal.
|
||||
*/
|
||||
@Test(dataProvider = "equal-duration")
|
||||
public void checkDurationEqual(String lexRepresentation1, String lexRepresentation2) {
|
||||
Duration duration1 = datatypeFactory.newDuration(lexRepresentation1);
|
||||
Duration duration2 = datatypeFactory.newDuration(lexRepresentation2);
|
||||
assertTrue(duration1.equals(duration2));
|
||||
}
|
||||
|
||||
@DataProvider(name = "greater-duration")
|
||||
public Object[][] getGreaterDuration() {
|
||||
return new Object[][] {
|
||||
{ "P1Y1M1DT1H1M2S", "P1Y1M1DT1H1M1S" },
|
||||
{ "P1Y1M1DT1H1M1S", "-P1Y1M1DT1H1M2S" },
|
||||
{ "P1Y1M1DT1H1M2S", "-P1Y1M1DT1H1M1S" },
|
||||
{ "-P1Y1M1DT1H1M1S", "-P1Y1M1DT1H1M2S" }, };
|
||||
}
|
||||
|
||||
/*
|
||||
* Test for compare() both durations valid and lhs > rhs.
|
||||
*/
|
||||
@Test(dataProvider = "greater-duration")
|
||||
public void checkDurationCompare(String lexRepresentation1, String lexRepresentation2) {
|
||||
Duration duration1 = datatypeFactory.newDuration(lexRepresentation1);
|
||||
Duration duration2 = datatypeFactory.newDuration(lexRepresentation2);
|
||||
assertTrue(duration1.compare(duration2) == DatatypeConstants.GREATER);
|
||||
}
|
||||
|
||||
@DataProvider(name = "not-equal-duration")
|
||||
public Object[][] getNotEqualDurations() {
|
||||
return new Object[][] {
|
||||
{ "P1Y1M1DT1H1M1S", "-P1Y1M1DT1H1M1S" },
|
||||
{ "P2Y1M1DT1H1M1S", "P1Y1M1DT1H1M1S" } };
|
||||
}
|
||||
|
||||
/*
|
||||
* Test for equals() both durations valid and lhs not equals rhs.
|
||||
*/
|
||||
@Test(dataProvider = "not-equal-duration")
|
||||
public void checkDurationNotEqual(String lexRepresentation1, String lexRepresentation2) {
|
||||
Duration duration1 = datatypeFactory.newDuration(lexRepresentation1);
|
||||
Duration duration2 = datatypeFactory.newDuration(lexRepresentation2);
|
||||
Assert.assertNotEquals(duration1, duration2);
|
||||
}
|
||||
|
||||
@DataProvider(name = "duration-sign")
|
||||
public Object[][] getDurationAndSign() {
|
||||
return new Object[][] {
|
||||
{ "P0Y0M0DT0H0M0S", 0 },
|
||||
{ "P1Y0M0DT0H0M0S", 1 },
|
||||
{ "-P1Y0M0DT0H0M0S", -1 } };
|
||||
}
|
||||
|
||||
/*
|
||||
* Test for Duration.getSign().
|
||||
*/
|
||||
@Test(dataProvider = "duration-sign")
|
||||
public void checkDurationSign(String lexRepresentation, int sign) {
|
||||
Duration duration = datatypeFactory.newDuration(lexRepresentation);
|
||||
assertEquals(duration.getSign(), sign);
|
||||
}
|
||||
|
||||
/*
|
||||
* Test for Duration.negate().
|
||||
*/
|
||||
@Test
|
||||
public void checkDurationNegate() {
|
||||
Duration durationPos = datatypeFactory.newDuration("P1Y0M0DT0H0M0S");
|
||||
Duration durationNeg = datatypeFactory.newDuration("-P1Y0M0DT0H0M0S");
|
||||
|
||||
assertEquals(durationPos.negate(), durationNeg);
|
||||
assertEquals(durationNeg.negate(), durationPos);
|
||||
assertEquals(durationPos.negate().negate(), durationPos);
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* Test for Duration.isShorterThan(Duration) and
|
||||
* Duration.isLongerThan(Duration).
|
||||
*/
|
||||
@Test
|
||||
public void checkDurationShorterLonger() {
|
||||
Duration shorter = datatypeFactory.newDuration("P1Y1M1DT1H1M1S");
|
||||
Duration longer = datatypeFactory.newDuration("P2Y1M1DT1H1M1S");
|
||||
|
||||
assertTrue(shorter.isShorterThan(longer));
|
||||
assertFalse(longer.isShorterThan(shorter));
|
||||
assertFalse(shorter.isShorterThan(shorter));
|
||||
|
||||
assertTrue(longer.isLongerThan(shorter));
|
||||
assertFalse(shorter.isLongerThan(longer));
|
||||
assertFalse(shorter.isLongerThan(shorter));
|
||||
}
|
||||
|
||||
/*
|
||||
* Test for Duration.isSet().
|
||||
*/
|
||||
@Test
|
||||
public void checkDurationIsSet() {
|
||||
Duration duration1 = datatypeFactory.newDuration(true, 1, 1, 1, 1, 1, 1);
|
||||
Duration duration2 = datatypeFactory.newDuration(true, 0, 0, 0, 0, 0, 0);
|
||||
|
||||
assertTrue(duration1.isSet(YEARS));
|
||||
assertTrue(duration1.isSet(MONTHS));
|
||||
assertTrue(duration1.isSet(DAYS));
|
||||
assertTrue(duration1.isSet(HOURS));
|
||||
assertTrue(duration1.isSet(MINUTES));
|
||||
assertTrue(duration1.isSet(SECONDS));
|
||||
|
||||
assertTrue(duration2.isSet(YEARS));
|
||||
assertTrue(duration2.isSet(MONTHS));
|
||||
assertTrue(duration2.isSet(DAYS));
|
||||
assertTrue(duration2.isSet(HOURS));
|
||||
assertTrue(duration2.isSet(MINUTES));
|
||||
assertTrue(duration2.isSet(SECONDS));
|
||||
|
||||
Duration duration66 = datatypeFactory.newDuration(true, null, null, zero, null, null, null);
|
||||
assertFalse(duration66.isSet(YEARS));
|
||||
assertFalse(duration66.isSet(MONTHS));
|
||||
assertFalse(duration66.isSet(HOURS));
|
||||
assertFalse(duration66.isSet(MINUTES));
|
||||
assertFalse(duration66.isSet(SECONDS));
|
||||
|
||||
Duration duration3 = datatypeFactory.newDuration("P1D");
|
||||
assertFalse(duration3.isSet(YEARS));
|
||||
assertFalse(duration3.isSet(MONTHS));
|
||||
assertFalse(duration3.isSet(HOURS));
|
||||
assertFalse(duration3.isSet(MINUTES));
|
||||
assertFalse(duration3.isSet(SECONDS));
|
||||
}
|
||||
|
||||
/*
|
||||
* Test Duration.isSet(Field) throws NPE if the field parameter is null.
|
||||
*/
|
||||
@Test(expectedExceptions = NullPointerException.class)
|
||||
public void checkDurationIsSetNeg() {
|
||||
Duration duration = datatypeFactory.newDuration(true, 0, 0, 0, 0, 0, 0);
|
||||
duration.isSet(null);
|
||||
}
|
||||
|
||||
/*
|
||||
* Test for -getField(DatatypeConstants.Field) DatatypeConstants.Field is
|
||||
* null - throws NPE.
|
||||
*/
|
||||
@Test(expectedExceptions = NullPointerException.class)
|
||||
public void checkDurationGetFieldNeg() {
|
||||
Duration duration67 = datatypeFactory.newDuration("P1Y1M1DT1H1M1S");
|
||||
duration67.getField(null);
|
||||
}
|
||||
|
||||
@DataProvider(name = "duration-fields")
|
||||
public Object[][] getDurationAndFields() {
|
||||
return new Object[][] {
|
||||
{ "P1Y1M1DT1H1M1S", one, one, one, one, one, new BigDecimal(one) },
|
||||
{ "PT1M", null, null, null, null, one, null },
|
||||
{ "P1M", null, one, null, null, null, null } };
|
||||
}
|
||||
|
||||
/*
|
||||
* Test for Duration.getField(DatatypeConstants.Field).
|
||||
*/
|
||||
@Test(dataProvider = "duration-fields")
|
||||
public void checkDurationGetField(String lexRepresentation, BigInteger years, BigInteger months, BigInteger days, BigInteger hours, BigInteger minutes,
|
||||
BigDecimal seconds) {
|
||||
Duration duration = datatypeFactory.newDuration(lexRepresentation);
|
||||
|
||||
assertEquals(duration.getField(YEARS), years);
|
||||
assertEquals(duration.getField(MONTHS), months);
|
||||
assertEquals(duration.getField(DAYS), days);
|
||||
assertEquals(duration.getField(HOURS), hours);
|
||||
assertEquals(duration.getField(MINUTES), minutes);
|
||||
assertEquals(duration.getField(SECONDS), seconds);
|
||||
}
|
||||
|
||||
@DataProvider(name = "number-string")
|
||||
public Object[][] getNumberAndString() {
|
||||
return new Object[][] {
|
||||
// is positive, year, month, day, hour, minute, second, lexical
|
||||
{ true, 1, 1, 1, 1, 1, 1, "P1Y1M1DT1H1M1S" },
|
||||
{ false, 1, 1, 1, 1, 1, 1, "-P1Y1M1DT1H1M1S" },
|
||||
{ true, 0, 0, 0, 0, 0, 0, "P0Y0M0DT0H0M0S" },
|
||||
{ false, 0, 0, 0, 0, 0, 0, "P0Y0M0DT0H0M0S" }
|
||||
};
|
||||
}
|
||||
|
||||
/*
|
||||
* Test for - toString().
|
||||
*/
|
||||
@Test(dataProvider = "number-string")
|
||||
public void checkDurationToString(boolean isPositive, int years, int months, int days, int hours, int minutes, int seconds, String lexical) {
|
||||
Duration duration = datatypeFactory.newDuration(isPositive, years, months, days, hours, minutes, seconds);
|
||||
assertEquals(duration.toString(), lexical);
|
||||
|
||||
assertEquals(datatypeFactory.newDuration(duration.toString()), duration);
|
||||
}
|
||||
|
||||
@DataProvider(name = "duration-field")
|
||||
public Object[][] getDurationAndField() {
|
||||
Function<Duration, Integer> getyears = duration -> duration.getYears();
|
||||
Function<Duration, Integer> getmonths = duration -> duration.getMonths();
|
||||
Function<Duration, Integer> getdays = duration -> duration.getDays();
|
||||
Function<Duration, Integer> gethours = duration -> duration.getHours();
|
||||
Function<Duration, Integer> getminutes = duration -> duration.getMinutes();
|
||||
Function<Duration, Integer> getseconds = duration -> duration.getSeconds();
|
||||
return new Object[][] {
|
||||
{ "P1Y1M1DT1H1M1S", getyears, 1 },
|
||||
{ "P1M1DT1H1M1S", getyears, 0 },
|
||||
{ "P1Y1M1DT1H1M1S", getmonths, 1 },
|
||||
{ "P1Y1DT1H1M1S", getmonths, 0 },
|
||||
{ "P1Y1M1DT1H1M1S", getdays, 1 },
|
||||
{ "P1Y1MT1H1M1S", getdays, 0 },
|
||||
{ "P1Y1M1DT1H1M1S", gethours, 1 },
|
||||
{ "P1Y1M1DT1M1S", gethours, 0 },
|
||||
{ "P1Y1M1DT1H1M1S", getminutes, 1 },
|
||||
{ "P1Y1M1DT1H1S", getminutes, 0 },
|
||||
{ "P1Y1M1DT1H1M1S", getseconds, 1 },
|
||||
{ "P1Y1M1DT1H1M", getseconds, 0 },
|
||||
{ "P1Y1M1DT1H1M100000000S", getseconds, 100000000 }, };
|
||||
}
|
||||
|
||||
/*
|
||||
* Test for Duration.getYears(), getMonths(), etc.
|
||||
*/
|
||||
@Test(dataProvider = "duration-field")
|
||||
public void checkDurationGetOneField(String lexRepresentation, Function<Duration, Integer> getter, int value) {
|
||||
Duration duration = datatypeFactory.newDuration(lexRepresentation);
|
||||
assertEquals(getter.apply(duration).intValue(), value);
|
||||
}
|
||||
|
||||
/*
|
||||
* Test for - getField(SECONDS)
|
||||
*/
|
||||
@Test
|
||||
public void checkDurationGetSecondsField() {
|
||||
Duration duration85 = datatypeFactory.newDuration("P1Y1M1DT1H1M100000000S");
|
||||
assertEquals((duration85.getField(SECONDS)).intValue(), 100000000);
|
||||
}
|
||||
|
||||
/*
|
||||
* getTimeInMillis(java.util.Calendar startInstant) returns milliseconds
|
||||
* between startInstant and startInstant plus this Duration.
|
||||
*/
|
||||
@Test
|
||||
public void checkDurationGetTimeInMillis() {
|
||||
Duration duration86 = datatypeFactory.newDuration("PT1M1S");
|
||||
Calendar calendar86 = Calendar.getInstance();
|
||||
assertEquals(duration86.getTimeInMillis(calendar86), 61000);
|
||||
}
|
||||
|
||||
/*
|
||||
* getTimeInMillis(java.util.Calendar startInstant) returns milliseconds
|
||||
* between startInstant and startInstant plus this Duration throws NPE if
|
||||
* startInstant parameter is null.
|
||||
*/
|
||||
@Test(expectedExceptions = NullPointerException.class)
|
||||
public void checkDurationGetTimeInMillisNeg() {
|
||||
Duration duration87 = datatypeFactory.newDuration("PT1M1S");
|
||||
Calendar calendar87 = null;
|
||||
duration87.getTimeInMillis(calendar87);
|
||||
}
|
||||
|
||||
@DataProvider(name = "duration-for-hash")
|
||||
public Object[][] getDurationsForHash() {
|
||||
return new Object[][] {
|
||||
{ "P1Y1M1DT1H1M1S", "P1Y1M1DT1H1M1S" },
|
||||
{ "P1D", "PT24H" },
|
||||
{ "PT1H", "PT60M" },
|
||||
{ "PT1M", "PT60S" },
|
||||
{ "P1Y", "P12M" } };
|
||||
}
|
||||
|
||||
/*
|
||||
* Test for Duration.hashcode(). hashcode() should return same value for
|
||||
* some equal durations.
|
||||
*/
|
||||
@Test(dataProvider = "duration-for-hash")
|
||||
public void checkDurationHashCode(String lexRepresentation1, String lexRepresentation2) {
|
||||
Duration duration1 = datatypeFactory.newDuration(lexRepresentation1);
|
||||
Duration duration2 = datatypeFactory.newDuration(lexRepresentation2);
|
||||
int hash1 = duration1.hashCode();
|
||||
int hash2 = duration2.hashCode();
|
||||
assertTrue(hash1 == hash2, " generated hash1 : " + hash1 + " generated hash2 : " + hash2);
|
||||
}
|
||||
|
||||
@DataProvider(name = "duration-for-add")
|
||||
public Object[][] getDurationsForAdd() {
|
||||
return new Object[][] {
|
||||
// initVal, addVal, resultVal
|
||||
{ "P1Y1M1DT1H1M1S", "P1Y1M1DT1H1M1S", "P2Y2M2DT2H2M2S" },
|
||||
{ "P1Y1M1DT1H1M1S", "-P1Y1M1DT1H1M1S", "P0Y0M0DT0H0M0S" },
|
||||
{ "-P1Y1M1DT1H1M1S", "-P1Y1M1DT1H1M1S", "-P2Y2M2DT2H2M2S" }, };
|
||||
}
|
||||
|
||||
/*
|
||||
* Test for add(Duration rhs).
|
||||
*/
|
||||
@Test(dataProvider = "duration-for-add")
|
||||
public void checkDurationAdd(String initVal, String addVal, String result) {
|
||||
Duration durationInit = datatypeFactory.newDuration(initVal);
|
||||
Duration durationAdd = datatypeFactory.newDuration(addVal);
|
||||
Duration durationResult = datatypeFactory.newDuration(result);
|
||||
|
||||
assertEquals(durationInit.add(durationAdd), durationResult);
|
||||
}
|
||||
|
||||
@DataProvider(name = "duration-for-addneg")
|
||||
public Object[][] getDurationsForAddNeg() {
|
||||
return new Object[][] {
|
||||
// initVal, addVal
|
||||
{ "P1Y1M1DT1H1M1S", null },
|
||||
{ "P1Y", "-P1D" },
|
||||
{ "-P1Y", "P1D" }, };
|
||||
}
|
||||
|
||||
/*
|
||||
* Test for add(Duration rhs) 'rhs' is null , should throw NPE. "1 year" +
|
||||
* "-1 day" or "-1 year" + "1 day" should throw IllegalStateException
|
||||
*/
|
||||
@Test(expectedExceptions = { NullPointerException.class, IllegalStateException.class }, dataProvider = "duration-for-addneg")
|
||||
public void checkDurationAddNeg(String initVal, String addVal) {
|
||||
Duration durationInit = datatypeFactory.newDuration(initVal);
|
||||
Duration durationAdd = addVal == null ? null : datatypeFactory.newDuration(addVal);
|
||||
|
||||
durationInit.add(durationAdd);
|
||||
}
|
||||
|
||||
/*
|
||||
* Test Duration#compare(Duration duration) with large durations.
|
||||
*
|
||||
* Bug # 4972785 UnsupportedOperationException is expected
|
||||
*
|
||||
*/
|
||||
@Test(expectedExceptions = UnsupportedOperationException.class)
|
||||
public void checkDurationCompareLarge() {
|
||||
String duration1Lex = "P100000000000000000000D";
|
||||
String duration2Lex = "PT2400000000000000000000H";
|
||||
|
||||
Duration duration1 = datatypeFactory.newDuration(duration1Lex);
|
||||
Duration duration2 = datatypeFactory.newDuration(duration2Lex);
|
||||
duration1.compare(duration2);
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* Test Duration#getXMLSchemaType().
|
||||
*
|
||||
* Bug # 5049544 Duration.getXMLSchemaType shall return the correct result
|
||||
*
|
||||
*/
|
||||
@Test
|
||||
public void checkDurationGetXMLSchemaType() {
|
||||
// DURATION
|
||||
Duration duration = datatypeFactory.newDuration("P1Y1M1DT1H1M1S");
|
||||
QName duration_xmlSchemaType = duration.getXMLSchemaType();
|
||||
assertEquals(duration_xmlSchemaType, DatatypeConstants.DURATION, "Expected DatatypeConstants.DURATION, returned " + duration_xmlSchemaType.toString());
|
||||
|
||||
// DURATION_DAYTIME
|
||||
Duration duration_dayTime = datatypeFactory.newDuration("P1DT1H1M1S");
|
||||
QName duration_dayTime_xmlSchemaType = duration_dayTime.getXMLSchemaType();
|
||||
assertEquals(duration_dayTime_xmlSchemaType, DatatypeConstants.DURATION_DAYTIME, "Expected DatatypeConstants.DURATION_DAYTIME, returned "
|
||||
+ duration_dayTime_xmlSchemaType.toString());
|
||||
|
||||
// DURATION_YEARMONTH
|
||||
Duration duration_yearMonth = datatypeFactory.newDuration("P1Y1M");
|
||||
QName duration_yearMonth_xmlSchemaType = duration_yearMonth.getXMLSchemaType();
|
||||
assertEquals(duration_yearMonth_xmlSchemaType, DatatypeConstants.DURATION_YEARMONTH, "Expected DatatypeConstants.DURATION_YEARMONTH, returned "
|
||||
+ duration_yearMonth_xmlSchemaType.toString());
|
||||
|
||||
}
|
||||
|
||||
|
||||
private final int undef = DatatypeConstants.FIELD_UNDEFINED;
|
||||
private final BigInteger zero = BigInteger.ZERO;
|
||||
private final BigInteger one = BigInteger.ONE;
|
||||
|
||||
}
|
@ -0,0 +1,74 @@
|
||||
/*
|
||||
* Copyright (c) 1999, 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.
|
||||
*/
|
||||
|
||||
package javax.xml.datatype.ptests;
|
||||
|
||||
import static org.testng.Assert.assertNotNull;
|
||||
|
||||
import javax.xml.datatype.DatatypeConfigurationException;
|
||||
import javax.xml.datatype.DatatypeFactory;
|
||||
import javax.xml.datatype.Duration;
|
||||
|
||||
import jaxp.library.JAXPDataProvider;
|
||||
import jaxp.library.JAXPBaseTest;
|
||||
|
||||
import org.testng.annotations.DataProvider;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
/*
|
||||
* @summary Tests for DatatypeFactory.newInstance(factoryClassName , classLoader)
|
||||
*/
|
||||
public class FactoryNewInstanceTest extends JAXPBaseTest {
|
||||
|
||||
private static final String DATATYPE_FACTORY_CLASSNAME = "com.sun.org.apache.xerces.internal.jaxp.datatype.DatatypeFactoryImpl";
|
||||
|
||||
@DataProvider(name = "parameters")
|
||||
public Object[][] getValidateParameters() {
|
||||
return new Object[][] { { DATATYPE_FACTORY_CLASSNAME, null }, { DATATYPE_FACTORY_CLASSNAME, this.getClass().getClassLoader() } };
|
||||
}
|
||||
|
||||
/*
|
||||
* test for DatatypeFactory.newInstance(java.lang.String factoryClassName,
|
||||
* java.lang.ClassLoader classLoader) factoryClassName points to correct
|
||||
* implementation of javax.xml.datatype.DatatypeFactory , should return
|
||||
* newInstance of DatatypeFactory
|
||||
*/
|
||||
@Test(dataProvider = "parameters")
|
||||
public void testNewInstance(String factoryClassName, ClassLoader classLoader) throws DatatypeConfigurationException {
|
||||
DatatypeFactory dtf = DatatypeFactory.newInstance(DATATYPE_FACTORY_CLASSNAME, null);
|
||||
Duration duration = dtf.newDuration(true, 1, 1, 1, 1, 1, 1);
|
||||
assertNotNull(duration);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* test for DatatypeFactory.newInstance(java.lang.String factoryClassName,
|
||||
* java.lang.ClassLoader classLoader) factoryClassName is null , should
|
||||
* throw DatatypeConfigurationException
|
||||
*/
|
||||
@Test(expectedExceptions = DatatypeConfigurationException.class, dataProvider = "new-instance-neg", dataProviderClass = JAXPDataProvider.class)
|
||||
public void testNewInstanceNeg(String factoryClassName, ClassLoader classLoader) throws DatatypeConfigurationException {
|
||||
DatatypeFactory.newInstance(factoryClassName, classLoader);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,356 @@
|
||||
/*
|
||||
* Copyright (c) 1999, 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.
|
||||
*/
|
||||
|
||||
package javax.xml.datatype.ptests;
|
||||
|
||||
import static java.util.Calendar.HOUR;
|
||||
import static java.util.Calendar.MINUTE;
|
||||
import static java.util.Calendar.YEAR;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
import static org.testng.Assert.assertTrue;
|
||||
|
||||
import java.util.GregorianCalendar;
|
||||
import java.util.Locale;
|
||||
import java.util.TimeZone;
|
||||
|
||||
import javax.xml.datatype.DatatypeConfigurationException;
|
||||
import javax.xml.datatype.DatatypeConstants;
|
||||
import javax.xml.datatype.DatatypeFactory;
|
||||
import javax.xml.datatype.Duration;
|
||||
import javax.xml.datatype.XMLGregorianCalendar;
|
||||
|
||||
import jaxp.library.JAXPBaseTest;
|
||||
|
||||
import org.testng.Assert;
|
||||
import org.testng.annotations.BeforeClass;
|
||||
import org.testng.annotations.DataProvider;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
/*
|
||||
* @bug 5049592 5041845 5048932 5064587 5040542 5049531 5049528
|
||||
* @summary Class containing the test cases for XMLGregorianCalendar
|
||||
*/
|
||||
public class XMLGregorianCalendarTest extends JAXPBaseTest {
|
||||
|
||||
private DatatypeFactory datatypeFactory;
|
||||
|
||||
@BeforeClass
|
||||
public void setup() throws DatatypeConfigurationException {
|
||||
datatypeFactory = DatatypeFactory.newInstance();
|
||||
}
|
||||
|
||||
@DataProvider(name = "valid-milliseconds")
|
||||
public Object[][] getValidMilliSeconds() {
|
||||
return new Object[][] { { 0 }, { 1 }, { 2 }, { 16 }, { 1000 } };
|
||||
}
|
||||
|
||||
/*
|
||||
* Test DatatypeFactory.newXMLGregorianCalendar(..) with milliseconds > 1.
|
||||
*
|
||||
* Bug # 5049592
|
||||
*
|
||||
*/
|
||||
@Test(dataProvider = "valid-milliseconds")
|
||||
public void checkNewCalendar(int ms) {
|
||||
// valid milliseconds
|
||||
XMLGregorianCalendar calendar = datatypeFactory.newXMLGregorianCalendar(2004, // year
|
||||
6, // month
|
||||
2, // day
|
||||
19, // hour
|
||||
20, // minute
|
||||
59, // second
|
||||
ms, // milliseconds
|
||||
840 // timezone
|
||||
);
|
||||
// expected success
|
||||
|
||||
assertEquals(calendar.getMillisecond(), ms);
|
||||
}
|
||||
|
||||
/*
|
||||
* Test DatatypeFactory.newXMLGregorianCalendarTime(..).
|
||||
*
|
||||
* Bug # 5049592
|
||||
*/
|
||||
@Test(dataProvider = "valid-milliseconds")
|
||||
public void checkNewTime(int ms) {
|
||||
// valid milliseconds
|
||||
XMLGregorianCalendar calendar2 = datatypeFactory.newXMLGregorianCalendarTime(19, // hour
|
||||
20, // minute
|
||||
59, // second
|
||||
ms, // milliseconds
|
||||
840 // timezone
|
||||
);
|
||||
// expected success
|
||||
|
||||
assertEquals(calendar2.getMillisecond(), ms);
|
||||
}
|
||||
|
||||
@DataProvider(name = "invalid-milliseconds")
|
||||
public Object[][] getInvalidMilliSeconds() {
|
||||
return new Object[][] { { -1 }, { 1001 } };
|
||||
}
|
||||
|
||||
/*
|
||||
* Test DatatypeFactory.newXMLGregorianCalendar(..).
|
||||
*
|
||||
* Bug # 5049592 IllegalArgumentException is thrown if milliseconds < 0 or >
|
||||
* 1001.
|
||||
*
|
||||
*/
|
||||
@Test(expectedExceptions = IllegalArgumentException.class, dataProvider = "invalid-milliseconds")
|
||||
public void checkNewCalendarNeg(int milliseconds) {
|
||||
// invalid milliseconds
|
||||
datatypeFactory.newXMLGregorianCalendar(2004, // year
|
||||
6, // month
|
||||
2, // day
|
||||
19, // hour
|
||||
20, // minute
|
||||
59, // second
|
||||
milliseconds, // milliseconds
|
||||
840 // timezone
|
||||
);
|
||||
}
|
||||
|
||||
/*
|
||||
* Test DatatypeFactory.newXMLGregorianCalendarTime(..).
|
||||
*
|
||||
* Bug # 5049592 IllegalArgumentException is thrown if milliseconds < 0 or >
|
||||
* 1001.
|
||||
*
|
||||
*/
|
||||
@Test(expectedExceptions = IllegalArgumentException.class, dataProvider = "invalid-milliseconds")
|
||||
public void checkNewTimeNeg(int milliseconds) {
|
||||
// invalid milliseconds
|
||||
datatypeFactory.newXMLGregorianCalendarTime(19, // hour
|
||||
20, // minute
|
||||
59, // second
|
||||
milliseconds, // milliseconds
|
||||
840 // timezone
|
||||
);
|
||||
}
|
||||
|
||||
@DataProvider(name = "data-for-add")
|
||||
public Object[][] getDataForAdd() {
|
||||
return new Object[][] {
|
||||
//calendar1, calendar2, duration
|
||||
{ "1999-12-31T00:00:00Z", "2000-01-01T00:00:00Z", "P1D" },
|
||||
{ "2000-12-31T00:00:00Z", "2001-01-01T00:00:00Z", "P1D" },
|
||||
{ "1998-12-31T00:00:00Z", "1999-01-01T00:00:00Z", "P1D" },
|
||||
{ "2001-12-31T00:00:00Z", "2002-01-01T00:00:00Z", "P1D" },
|
||||
{ "2003-04-11T00:00:00Z", "2003-04-12T00:00:00Z", "P1D" },
|
||||
{ "2003-04-11T00:00:00Z", "2003-04-14T00:00:00Z", "P3D" },
|
||||
{ "2003-04-30T00:00:00Z", "2003-05-01T00:00:00Z", "P1D" },
|
||||
{ "2003-02-28T00:00:00Z", "2003-03-01T00:00:00Z", "P1D" },
|
||||
{ "2000-02-29T00:00:00Z", "2000-03-01T00:00:00Z", "P1D" },
|
||||
{ "2000-02-28T00:00:00Z", "2000-02-29T00:00:00Z", "P1D" },
|
||||
{ "1998-01-11T00:00:00Z", "1998-04-11T00:00:00Z", "P90D" },
|
||||
{ "1999-05-11T00:00:00Z", "2002-05-11T00:00:00Z", "P1096D" }};
|
||||
}
|
||||
|
||||
/*
|
||||
* Test XMLGregorianCalendar.add(Duration).
|
||||
*
|
||||
*/
|
||||
@Test(dataProvider = "data-for-add")
|
||||
public void checkAddDays(String cal1, String cal2, String dur) {
|
||||
|
||||
XMLGregorianCalendar calendar1 = datatypeFactory.newXMLGregorianCalendar(cal1);
|
||||
XMLGregorianCalendar calendar2 = datatypeFactory.newXMLGregorianCalendar(cal2);
|
||||
|
||||
Duration duration = datatypeFactory.newDuration(dur);
|
||||
|
||||
XMLGregorianCalendar calendar1Clone = (XMLGregorianCalendar)calendar1.clone();
|
||||
|
||||
calendar1Clone.add(duration);
|
||||
assertEquals(calendar1Clone, calendar2);
|
||||
|
||||
calendar2.add(duration.negate());
|
||||
assertEquals(calendar2, calendar1);
|
||||
|
||||
}
|
||||
|
||||
@DataProvider(name = "gMonth")
|
||||
public Object[][] getGMonth() {
|
||||
return new Object[][] {
|
||||
{ "2000-02" },
|
||||
{ "2000-03" },
|
||||
{ "2018-02" }};
|
||||
}
|
||||
/*
|
||||
* Test XMLGregorianCalendar#isValid(). for gMonth
|
||||
*
|
||||
* Bug # 5041845
|
||||
*
|
||||
*/
|
||||
@Test(dataProvider = "gMonth")
|
||||
public void checkIsValid(String month) {
|
||||
|
||||
XMLGregorianCalendar gMonth = datatypeFactory.newXMLGregorianCalendar(month);
|
||||
gMonth.setYear(null);
|
||||
Assert.assertTrue(gMonth.isValid(), gMonth.toString() + " should isValid");
|
||||
|
||||
}
|
||||
|
||||
@DataProvider(name = "lexical01")
|
||||
public Object[][] getLexicalRepresentForNormalize01() {
|
||||
return new Object[][] { { "2000-01-16T12:00:00Z" }, { "2000-01-16T12:00:00" } };
|
||||
}
|
||||
|
||||
/*
|
||||
* Test XMLGregorianCalendar#normalize(...).
|
||||
*
|
||||
* Bug # 5048932 XMLGregorianCalendar.normalize works
|
||||
*
|
||||
*/
|
||||
@Test(dataProvider = "lexical01")
|
||||
public void checkNormalize01(String lexical) {
|
||||
XMLGregorianCalendar lhs = datatypeFactory.newXMLGregorianCalendar(lexical);
|
||||
lhs.normalize();
|
||||
}
|
||||
|
||||
@DataProvider(name = "lexical02")
|
||||
public Object[][] getLexicalRepresentForNormalize02() {
|
||||
return new Object[][] { { "2000-01-16T00:00:00.01Z" }, { "2000-01-16T00:00:00.01" }, { "13:20:00" } };
|
||||
}
|
||||
|
||||
/*
|
||||
* Test XMLGregorianCalendar#normalize(...).
|
||||
*
|
||||
* Bug # 5064587 XMLGregorianCalendar.normalize shall not change timezone
|
||||
*
|
||||
*/
|
||||
@Test(dataProvider = "lexical02")
|
||||
public void checkNormalize02(String lexical) {
|
||||
XMLGregorianCalendar orig = datatypeFactory.newXMLGregorianCalendar(lexical);
|
||||
XMLGregorianCalendar normalized = datatypeFactory.newXMLGregorianCalendar(lexical).normalize();
|
||||
|
||||
assertEquals(normalized.getTimezone(), orig.getTimezone());
|
||||
assertEquals(normalized.getMillisecond(), orig.getMillisecond());
|
||||
}
|
||||
|
||||
/*
|
||||
* Test XMLGregorianCalendar#toGregorianCalendar( TimeZone timezone, Locale
|
||||
* aLocale, XMLGregorianCalendar defaults)
|
||||
*
|
||||
* Bug # 5040542 the defaults XMLGregorianCalendar parameter shall take
|
||||
* effect
|
||||
*
|
||||
*/
|
||||
@Test
|
||||
public void checkToGregorianCalendar01() {
|
||||
|
||||
XMLGregorianCalendar time_16_17_18 = datatypeFactory.newXMLGregorianCalendar("16:17:18");
|
||||
XMLGregorianCalendar date_2001_02_03 = datatypeFactory.newXMLGregorianCalendar("2001-02-03");
|
||||
GregorianCalendar calendar = date_2001_02_03.toGregorianCalendar(null, null, time_16_17_18);
|
||||
|
||||
int year = calendar.get(YEAR);
|
||||
int minute = calendar.get(MINUTE);
|
||||
|
||||
assertTrue((year == 2001 && minute == 17), " expecting year == 2001, minute == 17" + ", result is year == " + year + ", minute == " + minute);
|
||||
|
||||
|
||||
calendar = time_16_17_18.toGregorianCalendar(null, null, date_2001_02_03);
|
||||
|
||||
year = calendar.get(YEAR);
|
||||
minute = calendar.get(MINUTE);
|
||||
|
||||
assertTrue((year == 2001 && minute == 17), " expecting year == 2001, minute == 17" + ", result is year == " + year + ", minute == " + minute);
|
||||
|
||||
|
||||
date_2001_02_03.setMinute(3);
|
||||
date_2001_02_03.setYear(null);
|
||||
|
||||
XMLGregorianCalendar date_time = datatypeFactory.newXMLGregorianCalendar("2003-04-11T02:13:01Z");
|
||||
|
||||
calendar = date_2001_02_03.toGregorianCalendar(null, null, date_time);
|
||||
|
||||
year = calendar.get(YEAR);
|
||||
minute = calendar.get(MINUTE);
|
||||
int hour = calendar.get(HOUR);
|
||||
|
||||
assertTrue((year == 2003 && hour == 2 && minute == 3), " expecting year == 2003, hour == 2, minute == 3" + ", result is year == " + year + ", hour == " + hour + ", minute == " + minute);
|
||||
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* Test XMLGregorianCalendar#toGregorianCalendar( TimeZone timezone, Locale
|
||||
* aLocale, XMLGregorianCalendar defaults) with the 'defaults' parameter
|
||||
* being null.
|
||||
*
|
||||
* Bug # 5049531 XMLGregorianCalendar.toGregorianCalendar(..) can accept
|
||||
* 'defaults' is null
|
||||
*
|
||||
*/
|
||||
@Test
|
||||
public void checkToGregorianCalendar02() {
|
||||
|
||||
XMLGregorianCalendar calendar = datatypeFactory.newXMLGregorianCalendar("2004-05-19T12:00:00+06:00");
|
||||
calendar.toGregorianCalendar(TimeZone.getDefault(), Locale.getDefault(), null);
|
||||
}
|
||||
|
||||
@DataProvider(name = "calendar")
|
||||
public Object[][] getXMLGregorianCalendarData() {
|
||||
return new Object[][] {
|
||||
// year, month, day, hour, minute, second
|
||||
{ 1970, 1, 1, 0, 0, 0 }, // DATETIME
|
||||
{ 1970, 1, 1, undef, undef, undef }, // DATE
|
||||
{ undef, undef, undef, 1, 0, 0 }, // TIME
|
||||
{ 1970, 1, undef, undef, undef, undef }, // GYEARMONTH
|
||||
{ undef, 1, 1, undef, undef, undef }, // GMONTHDAY
|
||||
{ 1970, undef, undef, undef, undef, undef }, // GYEAR
|
||||
{ undef, 1, undef, undef, undef, undef }, // GMONTH
|
||||
{ undef, undef, 1, undef, undef, undef } // GDAY
|
||||
};
|
||||
}
|
||||
|
||||
/*
|
||||
* Test XMLGregorianCalendar#toString()
|
||||
*
|
||||
* Bug # 5049528
|
||||
*
|
||||
*/
|
||||
@Test(dataProvider = "calendar")
|
||||
public void checkToStringPos(final int year, final int month, final int day, final int hour, final int minute, final int second) {
|
||||
XMLGregorianCalendar calendar = datatypeFactory.newXMLGregorianCalendar(year, month, day, hour, minute, second, undef, undef);
|
||||
calendar.toString();
|
||||
}
|
||||
|
||||
/*
|
||||
* Negative Test XMLGregorianCalendar#toString()
|
||||
*
|
||||
* Bug # 5049528 XMLGregorianCalendar.toString throws IllegalStateException
|
||||
* if all parameters are undef
|
||||
*
|
||||
*/
|
||||
@Test(expectedExceptions = IllegalStateException.class)
|
||||
public void checkToStringNeg() {
|
||||
XMLGregorianCalendar calendar = datatypeFactory.newXMLGregorianCalendar(undef, undef, undef, undef, undef, undef, undef, undef);
|
||||
// expected to fail
|
||||
calendar.toString();
|
||||
}
|
||||
|
||||
private final int undef = DatatypeConstants.FIELD_UNDEFINED;
|
||||
|
||||
}
|
@ -26,27 +26,38 @@ package javax.xml.parsers.ptests;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
import static org.testng.Assert.assertNotNull;
|
||||
import static org.testng.Assert.assertNull;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FilePermission;
|
||||
import java.io.FileReader;
|
||||
|
||||
import static javax.xml.XMLConstants.W3C_XML_SCHEMA_NS_URI;
|
||||
|
||||
import javax.xml.parsers.DocumentBuilder;
|
||||
import javax.xml.parsers.DocumentBuilderFactory;
|
||||
import javax.xml.parsers.FactoryConfigurationError;
|
||||
import javax.xml.parsers.ParserConfigurationException;
|
||||
import javax.xml.parsers.SAXParser;
|
||||
import javax.xml.parsers.SAXParserFactory;
|
||||
|
||||
import static javax.xml.parsers.ptests.ParserTestConst.GOLDEN_DIR;
|
||||
import static javax.xml.parsers.ptests.ParserTestConst.XML_DIR;
|
||||
|
||||
import javax.xml.transform.Transformer;
|
||||
import javax.xml.transform.TransformerFactory;
|
||||
import javax.xml.transform.dom.DOMSource;
|
||||
import javax.xml.transform.sax.SAXResult;
|
||||
|
||||
import jaxp.library.JAXPDataProvider;
|
||||
import jaxp.library.JAXPFileBaseTest;
|
||||
import static jaxp.library.JAXPTestUtilities.USER_DIR;
|
||||
import static jaxp.library.JAXPTestUtilities.compareWithGold;
|
||||
import static org.testng.Assert.assertFalse;
|
||||
import static org.testng.Assert.assertTrue;
|
||||
|
||||
import org.testng.annotations.DataProvider;
|
||||
import org.testng.annotations.Test;
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Element;
|
||||
@ -59,6 +70,52 @@ import org.xml.sax.helpers.DefaultHandler;
|
||||
* This checks the methods of DocumentBuilderFactoryImpl.
|
||||
*/
|
||||
public class DocumentBuilderFactoryTest extends JAXPFileBaseTest {
|
||||
/**
|
||||
* DocumentBuilderFactory implementation class name.
|
||||
*/
|
||||
private static final String DOCUMENT_BUILDER_FACTORY_CLASSNAME = "com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl";
|
||||
|
||||
/**
|
||||
* Provide valid DocumentBuilderFactory instantiation parameters.
|
||||
*
|
||||
* @return a data provider contains DocumentBuilderFactory instantiation parameters.
|
||||
*/
|
||||
@DataProvider(name = "parameters")
|
||||
public Object[][] getValidateParameters() {
|
||||
return new Object[][] { { DOCUMENT_BUILDER_FACTORY_CLASSNAME, null }, { DOCUMENT_BUILDER_FACTORY_CLASSNAME, this.getClass().getClassLoader() } };
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for DocumentBuilderFactory.newInstance(java.lang.String
|
||||
* factoryClassName, java.lang.ClassLoader classLoader) factoryClassName
|
||||
* points to correct implementation of
|
||||
* javax.xml.parsers.DocumentBuilderFactory , should return newInstance of
|
||||
* DocumentBuilderFactory
|
||||
*
|
||||
* @param factoryClassName
|
||||
* @param classLoader
|
||||
* @throws ParserConfigurationException
|
||||
*/
|
||||
@Test(dataProvider = "parameters")
|
||||
public void testNewInstance(String factoryClassName, ClassLoader classLoader) throws ParserConfigurationException {
|
||||
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(factoryClassName, classLoader);
|
||||
DocumentBuilder builder = dbf.newDocumentBuilder();
|
||||
assertNotNull(builder);
|
||||
}
|
||||
|
||||
/**
|
||||
* test for DocumentBuilderFactory.newInstance(java.lang.String
|
||||
* factoryClassName, java.lang.ClassLoader classLoader) factoryClassName is
|
||||
* null , should throw FactoryConfigurationError
|
||||
*
|
||||
* @param factoryClassName
|
||||
* @param classLoader
|
||||
*/
|
||||
@Test(expectedExceptions = FactoryConfigurationError.class, dataProvider = "new-instance-neg", dataProviderClass = JAXPDataProvider.class)
|
||||
public void testNewInstanceNeg(String factoryClassName, ClassLoader classLoader) {
|
||||
DocumentBuilderFactory.newInstance(factoryClassName, classLoader);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the default functionality of schema support method.
|
||||
* @throws Exception If any errors occur.
|
||||
|
@ -0,0 +1,75 @@
|
||||
/*
|
||||
* Copyright (c) 1999, 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.
|
||||
*/
|
||||
|
||||
package javax.xml.parsers.ptests;
|
||||
|
||||
import static org.testng.Assert.assertNotNull;
|
||||
|
||||
import javax.xml.parsers.FactoryConfigurationError;
|
||||
import javax.xml.parsers.ParserConfigurationException;
|
||||
import javax.xml.parsers.SAXParser;
|
||||
import javax.xml.parsers.SAXParserFactory;
|
||||
|
||||
import jaxp.library.JAXPDataProvider;
|
||||
import jaxp.library.JAXPBaseTest;
|
||||
|
||||
import org.testng.annotations.DataProvider;
|
||||
import org.testng.annotations.Test;
|
||||
import org.xml.sax.SAXException;
|
||||
|
||||
/*
|
||||
* @summary Tests for SAXParserFactory.newInstance(factoryClassName , classLoader)
|
||||
*/
|
||||
public class SAXFactoryNewInstanceTest extends JAXPBaseTest {
|
||||
|
||||
private static final String SAXPARSER_FACTORY_CLASSNAME = "com.sun.org.apache.xerces.internal.jaxp.SAXParserFactoryImpl";
|
||||
|
||||
@DataProvider(name = "parameters")
|
||||
public Object[][] getValidateParameters() {
|
||||
return new Object[][] { { SAXPARSER_FACTORY_CLASSNAME, null }, { SAXPARSER_FACTORY_CLASSNAME, this.getClass().getClassLoader() } };
|
||||
}
|
||||
|
||||
/*
|
||||
* test for SAXParserFactory.newInstance(java.lang.String factoryClassName,
|
||||
* java.lang.ClassLoader classLoader) factoryClassName points to correct
|
||||
* implementation of javax.xml.parsers.SAXParserFactory , should return
|
||||
* newInstance of SAXParserFactory
|
||||
*/
|
||||
@Test(dataProvider = "parameters")
|
||||
public void testNewInstance(String factoryClassName, ClassLoader classLoader) throws ParserConfigurationException, SAXException {
|
||||
SAXParserFactory spf = SAXParserFactory.newInstance(factoryClassName, classLoader);
|
||||
SAXParser sp = spf.newSAXParser();
|
||||
assertNotNull(sp);
|
||||
}
|
||||
|
||||
/*
|
||||
* test for SAXParserFactory.newInstance(java.lang.String factoryClassName,
|
||||
* java.lang.ClassLoader classLoader) factoryClassName is null , should
|
||||
* throw FactoryConfigurationError
|
||||
*/
|
||||
@Test(expectedExceptions = FactoryConfigurationError.class, dataProvider = "new-instance-neg", dataProviderClass = JAXPDataProvider.class)
|
||||
public void testNewInstanceNeg(String factoryClassName, ClassLoader classLoader) {
|
||||
SAXParserFactory.newInstance(factoryClassName, classLoader);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,76 @@
|
||||
/*
|
||||
* Copyright (c) 1999, 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.
|
||||
*/
|
||||
|
||||
package javax.xml.stream.ptests;
|
||||
|
||||
import static org.testng.Assert.assertNotNull;
|
||||
|
||||
import javax.xml.stream.XMLEventFactory;
|
||||
|
||||
import jaxp.library.JAXPDataProvider;
|
||||
import jaxp.library.JAXPBaseTest;
|
||||
|
||||
import org.testng.annotations.DataProvider;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
/*
|
||||
* @summary Tests for XMLEventFactory.newFactory(factoryId , classLoader)
|
||||
*/
|
||||
public class XMLEventFactoryNewInstanceTest extends JAXPBaseTest {
|
||||
|
||||
private static final String XMLEVENT_FACTORY_CLASSNAME = "com.sun.xml.internal.stream.events.XMLEventFactoryImpl";
|
||||
private static final String XMLEVENT_FACRORY_ID = "javax.xml.stream.XMLEventFactory";
|
||||
|
||||
@DataProvider(name = "parameters")
|
||||
public Object[][] getValidateParameters() {
|
||||
return new Object[][] { { XMLEVENT_FACRORY_ID, null }, { XMLEVENT_FACRORY_ID, this.getClass().getClassLoader() } };
|
||||
}
|
||||
|
||||
/*
|
||||
* test for XMLEventFactory.newFactory(java.lang.String factoryClassName,
|
||||
* java.lang.ClassLoader classLoader) factoryClassName points to correct
|
||||
* implementation of javax.xml.stream.XMLEventFactory , should return
|
||||
* newInstance of XMLEventFactory
|
||||
*/
|
||||
@Test(dataProvider = "parameters")
|
||||
public void testNewFactory(String factoryId, ClassLoader classLoader) {
|
||||
setSystemProperty(XMLEVENT_FACRORY_ID, XMLEVENT_FACTORY_CLASSNAME);
|
||||
try {
|
||||
XMLEventFactory xef = XMLEventFactory.newFactory(factoryId, classLoader);
|
||||
assertNotNull(xef);
|
||||
} finally {
|
||||
setSystemProperty(XMLEVENT_FACRORY_ID, null);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* test for XMLEventFactory.newFactory(java.lang.String factoryClassName,
|
||||
* java.lang.ClassLoader classLoader) factoryClassName is null , should
|
||||
* throw NullPointerException
|
||||
*/
|
||||
@Test(expectedExceptions = NullPointerException.class, dataProvider = "new-instance-neg", dataProviderClass = JAXPDataProvider.class)
|
||||
public void testNewFactoryNeg(String factoryId, ClassLoader classLoader) {
|
||||
XMLEventFactory.newFactory(null, null);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,76 @@
|
||||
/*
|
||||
* Copyright (c) 1999, 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.
|
||||
*/
|
||||
|
||||
package javax.xml.stream.ptests;
|
||||
|
||||
import static org.testng.Assert.assertNotNull;
|
||||
|
||||
import javax.xml.stream.XMLInputFactory;
|
||||
|
||||
import jaxp.library.JAXPDataProvider;
|
||||
import jaxp.library.JAXPBaseTest;
|
||||
|
||||
import org.testng.annotations.DataProvider;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
/*
|
||||
* @summary Tests for XMLInputFactory.newFactory(factoryId , classLoader)
|
||||
*/
|
||||
public class XMLInputFactoryNewInstanceTest extends JAXPBaseTest {
|
||||
|
||||
private static final String XMLINPUT_FACTORY_CLASSNAME = "com.sun.xml.internal.stream.XMLInputFactoryImpl";
|
||||
private static final String XMLINPUT_FACRORY_ID = "javax.xml.stream.XMLInputFactory";
|
||||
|
||||
@DataProvider(name = "parameters")
|
||||
public Object[][] getValidateParameters() {
|
||||
return new Object[][] { { XMLINPUT_FACRORY_ID, null }, { XMLINPUT_FACRORY_ID, this.getClass().getClassLoader() } };
|
||||
}
|
||||
|
||||
/*
|
||||
* test for XMLInputFactory.newFactory(java.lang.String factoryId,
|
||||
* java.lang.ClassLoader classLoader) factoryClassName points to correct
|
||||
* implementation of javax.xml.stream.XMLInputFactory , should return
|
||||
* newInstance of XMLInputFactory
|
||||
*/
|
||||
@Test(dataProvider = "parameters")
|
||||
public void testNewFactory(String factoryId, ClassLoader classLoader) {
|
||||
setSystemProperty(XMLINPUT_FACRORY_ID, XMLINPUT_FACTORY_CLASSNAME);
|
||||
try {
|
||||
XMLInputFactory xif = XMLInputFactory.newFactory(factoryId, classLoader);
|
||||
assertNotNull(xif);
|
||||
} finally {
|
||||
setSystemProperty(XMLINPUT_FACRORY_ID, null);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* test for XMLInputFactory.newFactory(java.lang.String factoryClassName,
|
||||
* java.lang.ClassLoader classLoader) factoryClassName is null , should
|
||||
* throw NullPointerException
|
||||
*/
|
||||
@Test(expectedExceptions = NullPointerException.class, dataProvider = "new-instance-neg", dataProviderClass = JAXPDataProvider.class)
|
||||
public void testNewFactoryNeg(String factoryId, ClassLoader classLoader) {
|
||||
XMLInputFactory.newFactory(factoryId, classLoader);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,64 @@
|
||||
/*
|
||||
* Copyright (c) 1999, 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.
|
||||
*/
|
||||
|
||||
package javax.xml.transform.ptests;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.File;
|
||||
|
||||
import javax.xml.parsers.DocumentBuilder;
|
||||
import javax.xml.parsers.DocumentBuilderFactory;
|
||||
import javax.xml.transform.Transformer;
|
||||
import javax.xml.transform.TransformerFactory;
|
||||
import javax.xml.transform.dom.DOMSource;
|
||||
import javax.xml.transform.stream.StreamResult;
|
||||
import javax.xml.transform.stream.StreamSource;
|
||||
|
||||
import jaxp.library.JAXPFileBaseTest;
|
||||
import static javax.xml.transform.ptests.TransformerTestConst.XML_DIR;
|
||||
|
||||
import org.testng.annotations.Test;
|
||||
import org.w3c.dom.Document;
|
||||
|
||||
/*
|
||||
* @bug 6384418
|
||||
* @summary verify the transforming won't throw any exception
|
||||
*/
|
||||
public class Bug6384418Test extends JAXPFileBaseTest {
|
||||
|
||||
@Test
|
||||
public void test() throws Exception {
|
||||
TransformerFactory tfactory = TransformerFactory.newInstance();
|
||||
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
|
||||
dbf.setNamespaceAware(true);
|
||||
DocumentBuilder db = dbf.newDocumentBuilder();
|
||||
Document document = db.parse(new File(XML_DIR + "dataentry.xsl"));
|
||||
DOMSource domSource = new DOMSource(document);
|
||||
|
||||
Transformer transformer = tfactory.newTransformer(domSource);
|
||||
StreamSource streamSource = new StreamSource(new File(XML_DIR + "test.xml"));
|
||||
StreamResult streamResult = new StreamResult(new ByteArrayOutputStream());
|
||||
transformer.transform(streamSource, streamResult);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,383 @@
|
||||
/*
|
||||
* Copyright (c) 1999, 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.
|
||||
*/
|
||||
|
||||
package javax.xml.transform.ptests;
|
||||
|
||||
import static javax.xml.transform.ptests.TransformerTestConst.XML_DIR;
|
||||
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.io.OutputStreamWriter;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import javax.xml.parsers.DocumentBuilder;
|
||||
import javax.xml.parsers.DocumentBuilderFactory;
|
||||
import javax.xml.parsers.ParserConfigurationException;
|
||||
import javax.xml.stream.XMLEventWriter;
|
||||
import javax.xml.stream.XMLInputFactory;
|
||||
import javax.xml.stream.XMLOutputFactory;
|
||||
import javax.xml.stream.XMLStreamException;
|
||||
import javax.xml.stream.XMLStreamReader;
|
||||
import javax.xml.stream.XMLStreamWriter;
|
||||
import javax.xml.transform.Result;
|
||||
import javax.xml.transform.Source;
|
||||
import javax.xml.transform.Transformer;
|
||||
import javax.xml.transform.TransformerConfigurationException;
|
||||
import javax.xml.transform.TransformerFactory;
|
||||
import javax.xml.transform.dom.DOMSource;
|
||||
import javax.xml.transform.sax.SAXResult;
|
||||
import javax.xml.transform.sax.SAXSource;
|
||||
import javax.xml.transform.stax.StAXResult;
|
||||
import javax.xml.transform.stax.StAXSource;
|
||||
import javax.xml.transform.stream.StreamResult;
|
||||
import javax.xml.transform.stream.StreamSource;
|
||||
|
||||
import jaxp.library.JAXPFileBaseTest;
|
||||
|
||||
import org.testng.annotations.BeforeClass;
|
||||
import org.testng.annotations.DataProvider;
|
||||
import org.testng.annotations.Test;
|
||||
import org.w3c.dom.Document;
|
||||
import org.xml.sax.Attributes;
|
||||
import org.xml.sax.ContentHandler;
|
||||
import org.xml.sax.InputSource;
|
||||
import org.xml.sax.Locator;
|
||||
import org.xml.sax.SAXException;
|
||||
|
||||
/*
|
||||
* @summary Tests for variable combination of Transformer.transform(Source, Result)
|
||||
*/
|
||||
@Test(singleThreaded = true)
|
||||
public class TransformTest extends JAXPFileBaseTest {
|
||||
|
||||
/*
|
||||
* Initialize the share objects.
|
||||
*/
|
||||
@BeforeClass
|
||||
public void setup() throws Exception {
|
||||
ifac = XMLInputFactory.newInstance();
|
||||
ofac = XMLOutputFactory.newInstance();
|
||||
tfac = TransformerFactory.newInstance();
|
||||
|
||||
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
|
||||
dbf.setNamespaceAware(true);
|
||||
db = dbf.newDocumentBuilder();
|
||||
|
||||
xml = Files.readAllBytes(Paths.get(XML_DIR + "cities.xml"));
|
||||
template = Files.readAllBytes(Paths.get(XML_DIR + "cities.xsl"));
|
||||
|
||||
xmlDoc = db.parse(xmlInputStream());
|
||||
}
|
||||
|
||||
@DataProvider(name = "input-provider")
|
||||
public Object[][] prepareTestCombination() throws Exception {
|
||||
|
||||
Supplier<Source> staxStreamSource = () -> new StAXSource(getXMLStreamReader());
|
||||
Supplier<Source> staxEventSource = this::getStAXEventSource;
|
||||
Supplier<Source> domSource = () -> new DOMSource(xmlDoc);
|
||||
Supplier<Source> saxSource = () -> new SAXSource(new InputSource(xmlInputStream()));
|
||||
Supplier<Source> streamSource = () -> new StreamSource(xmlInputStream());
|
||||
|
||||
Supplier<Result> staxStreamResult = () -> new StAXResult(getXMLStreamWriter());
|
||||
Supplier<Result> staxEventResult = () -> new StAXResult(getXMLEventWriter());
|
||||
Supplier<Result> saxResult = this::getHandlerSAXResult;
|
||||
Supplier<Result> streamResult = () -> new StreamResult(transOutputStream());
|
||||
|
||||
Transformer domTemplateTransformer = createTransformer(getDomTemplate());
|
||||
Transformer saxTemplateTransformer = createTransformer(getSAXTemplate());
|
||||
Transformer streamTemplateTransformer = createTransformer(getStreamTemplate());
|
||||
Transformer noTemplateTransformer = createTransformer(null);
|
||||
Transformer staxStreamTemplateTransformer = createTransformer(getStAXStreamTemplate());
|
||||
Transformer staxEventTemplateTransformer = createTransformer(getStAXEventTemplate());
|
||||
|
||||
return new Object[][] {
|
||||
// StAX Stream
|
||||
{ staxStreamSource, staxStreamResult, domTemplateTransformer },
|
||||
{ staxStreamSource, staxStreamResult, saxTemplateTransformer },
|
||||
{ staxStreamSource, staxStreamResult, streamTemplateTransformer },
|
||||
{ staxStreamSource, staxStreamResult, noTemplateTransformer },
|
||||
{ staxStreamSource, staxStreamResult, staxStreamTemplateTransformer },
|
||||
{ staxStreamSource, saxResult, domTemplateTransformer },
|
||||
{ staxStreamSource, streamResult, domTemplateTransformer },
|
||||
{ domSource, staxStreamResult, domTemplateTransformer },
|
||||
{ saxSource, staxStreamResult, domTemplateTransformer },
|
||||
{ streamSource, staxStreamResult, domTemplateTransformer },
|
||||
{ staxStreamSource, streamResult, saxTemplateTransformer },
|
||||
{ domSource, staxStreamResult, saxTemplateTransformer },
|
||||
{ saxSource, staxStreamResult, saxTemplateTransformer },
|
||||
{ streamSource, staxStreamResult, saxTemplateTransformer },
|
||||
{ staxStreamSource, streamResult, streamTemplateTransformer },
|
||||
{ domSource, staxStreamResult, streamTemplateTransformer },
|
||||
{ saxSource, staxStreamResult, streamTemplateTransformer },
|
||||
{ streamSource, staxStreamResult, streamTemplateTransformer },
|
||||
// StAX Event
|
||||
{ staxEventSource, staxEventResult, domTemplateTransformer },
|
||||
{ staxEventSource, staxEventResult, saxTemplateTransformer },
|
||||
{ staxEventSource, staxEventResult, streamTemplateTransformer },
|
||||
{ staxEventSource, staxEventResult, noTemplateTransformer },
|
||||
{ staxEventSource, staxEventResult, staxEventTemplateTransformer },
|
||||
{ staxEventSource, saxResult, domTemplateTransformer },
|
||||
{ staxEventSource, streamResult, domTemplateTransformer },
|
||||
{ domSource, staxEventResult, domTemplateTransformer },
|
||||
{ saxSource, staxEventResult, domTemplateTransformer },
|
||||
{ streamSource, staxEventResult, domTemplateTransformer },
|
||||
{ staxEventSource, streamResult, saxTemplateTransformer },
|
||||
{ domSource, staxEventResult, saxTemplateTransformer },
|
||||
{ saxSource, staxEventResult, saxTemplateTransformer },
|
||||
{ streamSource, staxEventResult, saxTemplateTransformer },
|
||||
{ staxEventSource, streamResult, streamTemplateTransformer },
|
||||
{ domSource, staxEventResult, streamTemplateTransformer },
|
||||
{ saxSource, staxEventResult, streamTemplateTransformer },
|
||||
{ streamSource, staxEventResult, streamTemplateTransformer } };
|
||||
}
|
||||
|
||||
/*
|
||||
* run Transformer.transform(Source, Result)
|
||||
*/
|
||||
@Test(dataProvider = "input-provider")
|
||||
public void testTransform(Supplier<Source> src, Supplier<Result> res, Transformer transformer) throws Throwable {
|
||||
try {
|
||||
transformer.transform(src.get(), res.get());
|
||||
} catch (WrapperException e) {
|
||||
throw e.getCause();
|
||||
}
|
||||
}
|
||||
|
||||
private InputStream xmlInputStream() {
|
||||
return new ByteArrayInputStream(xml);
|
||||
}
|
||||
|
||||
private InputStream templateInputStream() {
|
||||
return new ByteArrayInputStream(template);
|
||||
}
|
||||
|
||||
private OutputStream transOutputStream() {
|
||||
return new ByteArrayOutputStream(xml.length);
|
||||
}
|
||||
|
||||
private XMLStreamReader getXMLStreamReader() {
|
||||
try {
|
||||
return ifac.createXMLStreamReader(xmlInputStream());
|
||||
} catch (XMLStreamException e) {
|
||||
throw new WrapperException(e);
|
||||
}
|
||||
}
|
||||
|
||||
private XMLStreamWriter getXMLStreamWriter() {
|
||||
try {
|
||||
return ofac.createXMLStreamWriter(transOutputStream());
|
||||
} catch (XMLStreamException e) {
|
||||
throw new WrapperException(e);
|
||||
}
|
||||
}
|
||||
|
||||
private StAXSource getStAXEventSource() {
|
||||
try {
|
||||
return new StAXSource(ifac.createXMLEventReader(xmlInputStream()));
|
||||
} catch (XMLStreamException e) {
|
||||
throw new WrapperException(e);
|
||||
}
|
||||
}
|
||||
|
||||
private XMLEventWriter getXMLEventWriter() {
|
||||
try {
|
||||
return ofac.createXMLEventWriter(transOutputStream());
|
||||
} catch (XMLStreamException e) {
|
||||
throw new WrapperException(e);
|
||||
}
|
||||
}
|
||||
|
||||
private SAXResult getHandlerSAXResult() {
|
||||
SAXResult res = new SAXResult();
|
||||
MyContentHandler myContentHandler = new MyContentHandler(transOutputStream());
|
||||
res.setHandler(myContentHandler);
|
||||
return res;
|
||||
}
|
||||
|
||||
private Source getDomTemplate() throws SAXException, IOException {
|
||||
return new DOMSource(db.parse(templateInputStream()));
|
||||
}
|
||||
|
||||
private Source getSAXTemplate() {
|
||||
return new SAXSource(new InputSource(templateInputStream()));
|
||||
}
|
||||
|
||||
private Source getStreamTemplate() {
|
||||
return new StreamSource(templateInputStream());
|
||||
}
|
||||
|
||||
private Source getStAXStreamTemplate() throws XMLStreamException {
|
||||
return new StAXSource(ifac.createXMLStreamReader(templateInputStream()));
|
||||
}
|
||||
|
||||
private Source getStAXEventTemplate() throws XMLStreamException {
|
||||
return new StAXSource(ifac.createXMLEventReader(templateInputStream()));
|
||||
}
|
||||
|
||||
private Transformer createTransformer(Source templateSource) throws TransformerConfigurationException {
|
||||
Transformer transformer = (templateSource == null) ? tfac.newTransformer() : tfac.newTransformer(templateSource);
|
||||
transformer.setOutputProperty("indent", "yes");
|
||||
return transformer;
|
||||
|
||||
}
|
||||
|
||||
private static class MyContentHandler implements ContentHandler {
|
||||
private BufferedWriter bWriter;
|
||||
|
||||
public MyContentHandler(OutputStream os) {
|
||||
bWriter = new BufferedWriter(new OutputStreamWriter(os));
|
||||
}
|
||||
|
||||
public void setDocumentLocator(Locator locator) {
|
||||
}
|
||||
|
||||
public void startDocument() throws SAXException {
|
||||
String str = "startDocument";
|
||||
try {
|
||||
bWriter.write(str, 0, str.length());
|
||||
bWriter.newLine();
|
||||
} catch (IOException e) {
|
||||
System.out.println("bWriter error");
|
||||
}
|
||||
}
|
||||
|
||||
public void endDocument() throws SAXException {
|
||||
String str = "endDocument";
|
||||
try {
|
||||
bWriter.write(str, 0, str.length());
|
||||
bWriter.newLine();
|
||||
bWriter.flush();
|
||||
bWriter.close();
|
||||
} catch (IOException e) {
|
||||
System.out.println("bWriter error");
|
||||
}
|
||||
}
|
||||
|
||||
public void startPrefixMapping(String prefix, String uri) throws SAXException {
|
||||
String str = "startPrefixMapping: " + prefix + ", " + uri;
|
||||
try {
|
||||
bWriter.write(str, 0, str.length());
|
||||
bWriter.newLine();
|
||||
} catch (IOException e) {
|
||||
System.out.println("bWriter error");
|
||||
}
|
||||
}
|
||||
|
||||
public void endPrefixMapping(String prefix) throws SAXException {
|
||||
String str = "endPrefixMapping: " + prefix;
|
||||
try {
|
||||
bWriter.write(str, 0, str.length());
|
||||
bWriter.newLine();
|
||||
} catch (IOException e) {
|
||||
System.out.println("bWriter error");
|
||||
}
|
||||
}
|
||||
|
||||
public void startElement(String namespaceURI, String localName, String qName, Attributes atts) throws SAXException {
|
||||
StringBuilder str = new StringBuilder("startElement: ").append(namespaceURI).append(", ").append(namespaceURI).append(", ").append(qName).append(" : ");
|
||||
int n = atts.getLength();
|
||||
for (int i = 0; i < n; i++) {
|
||||
str.append(", ").append(atts.getQName(i)).append(" : ").append(atts.getValue(i));
|
||||
}
|
||||
|
||||
try {
|
||||
bWriter.write(str.toString(), 0, str.length());
|
||||
bWriter.newLine();
|
||||
} catch (IOException e) {
|
||||
System.out.println("bWriter error");
|
||||
}
|
||||
}
|
||||
|
||||
public void endElement(String namespaceURI, String localName, String qName) throws SAXException {
|
||||
String str = "endElement: " + namespaceURI + ", " + namespaceURI + ", " + qName;
|
||||
try {
|
||||
bWriter.write(str, 0, str.length());
|
||||
bWriter.newLine();
|
||||
} catch (IOException e) {
|
||||
System.out.println("bWriter error");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void characters(char ch[], int start, int length) throws SAXException {
|
||||
String str = new String(ch, start, length);
|
||||
try {
|
||||
bWriter.write(str, 0, str.length());
|
||||
bWriter.newLine();
|
||||
} catch (IOException e) {
|
||||
System.out.println("bWriter error");
|
||||
}
|
||||
}
|
||||
|
||||
public void ignorableWhitespace(char ch[], int start, int length) throws SAXException {
|
||||
String str = "ignorableWhitespace";
|
||||
try {
|
||||
bWriter.write(str, 0, str.length());
|
||||
bWriter.newLine();
|
||||
} catch (IOException e) {
|
||||
System.out.println("bWriter error");
|
||||
}
|
||||
}
|
||||
|
||||
public void processingInstruction(String target, String data) throws SAXException {
|
||||
String str = "processingInstruction: " + target + ", " + target;
|
||||
try {
|
||||
bWriter.write(str, 0, str.length());
|
||||
bWriter.newLine();
|
||||
} catch (IOException e) {
|
||||
System.out.println("bWriter error");
|
||||
}
|
||||
}
|
||||
|
||||
public void skippedEntity(String name) throws SAXException {
|
||||
String str = "skippedEntity: " + name;
|
||||
try {
|
||||
bWriter.write(str, 0, str.length());
|
||||
bWriter.newLine();
|
||||
} catch (IOException e) {
|
||||
System.out.println("bWriter error");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static class WrapperException extends RuntimeException {
|
||||
public WrapperException(Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
}
|
||||
|
||||
private XMLInputFactory ifac;
|
||||
private XMLOutputFactory ofac;
|
||||
private TransformerFactory tfac;
|
||||
private DocumentBuilder db;
|
||||
private byte[] xml;
|
||||
private byte[] template;
|
||||
private Document xmlDoc;
|
||||
|
||||
}
|
@ -23,25 +23,78 @@
|
||||
package javax.xml.transform.ptests;
|
||||
|
||||
import java.io.*;
|
||||
import java.io.FileOutputStream;
|
||||
|
||||
import javax.xml.parsers.*;
|
||||
import javax.xml.transform.*;
|
||||
import javax.xml.transform.dom.*;
|
||||
|
||||
import static javax.xml.transform.ptests.TransformerTestConst.GOLDEN_DIR;
|
||||
import static javax.xml.transform.ptests.TransformerTestConst.XML_DIR;
|
||||
|
||||
import javax.xml.transform.stream.*;
|
||||
|
||||
import jaxp.library.JAXPDataProvider;
|
||||
import jaxp.library.JAXPFileBaseTest;
|
||||
import static jaxp.library.JAXPTestUtilities.USER_DIR;
|
||||
import static jaxp.library.JAXPTestUtilities.compareWithGold;
|
||||
import static org.testng.Assert.assertNotNull;
|
||||
import static org.testng.Assert.assertTrue;
|
||||
|
||||
import org.testng.annotations.DataProvider;
|
||||
import org.testng.annotations.Test;
|
||||
import org.w3c.dom.*;
|
||||
|
||||
/**
|
||||
* Class containing the test cases for TransformerFactory API's
|
||||
* getAssociatedStyleSheet method.
|
||||
* getAssociatedStyleSheet method and TransformerFactory.newInstance(factoryClassName , classLoader).
|
||||
*/
|
||||
public class TransformerFactoryTest extends JAXPFileBaseTest {
|
||||
/**
|
||||
* TransformerFactory implementation class name.
|
||||
*/
|
||||
private static final String TRANSFORMER_FACTORY_CLASSNAME = "com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl";
|
||||
|
||||
/**
|
||||
* Provide valid TransformerFactory instantiation parameters.
|
||||
*
|
||||
* @return a data provider contains TransformerFactory instantiation parameters.
|
||||
*/
|
||||
@DataProvider(name = "parameters")
|
||||
public Object[][] getValidateParameters() {
|
||||
return new Object[][] { { TRANSFORMER_FACTORY_CLASSNAME, null }, { TRANSFORMER_FACTORY_CLASSNAME, this.getClass().getClassLoader() } };
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for TransformerFactory.newInstance(java.lang.String
|
||||
* factoryClassName, java.lang.ClassLoader classLoader) factoryClassName
|
||||
* points to correct implementation of
|
||||
* javax.xml.transform.TransformerFactory , should return newInstance of
|
||||
* TransformerFactory
|
||||
*
|
||||
* @param factoryClassName
|
||||
* @param classLoader
|
||||
* @throws TransformerConfigurationException
|
||||
*/
|
||||
@Test(dataProvider = "parameters")
|
||||
public void testNewInstance(String factoryClassName, ClassLoader classLoader) throws TransformerConfigurationException {
|
||||
TransformerFactory tf = TransformerFactory.newInstance(factoryClassName, classLoader);
|
||||
Transformer transformer = tf.newTransformer();
|
||||
assertNotNull(transformer);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for TransformerFactory.newInstance(java.lang.String
|
||||
* factoryClassName, java.lang.ClassLoader classLoader) factoryClassName is
|
||||
* null , should throw TransformerFactoryConfigurationError
|
||||
*
|
||||
* @param factoryClassName
|
||||
* @param classLoader
|
||||
*/
|
||||
@Test(expectedExceptions = TransformerFactoryConfigurationError.class, dataProvider = "new-instance-neg", dataProviderClass = JAXPDataProvider.class)
|
||||
public void testNewInstanceNeg(String factoryClassName, ClassLoader classLoader) {
|
||||
TransformerFactory.newInstance(factoryClassName, classLoader);
|
||||
}
|
||||
|
||||
/**
|
||||
* This test case checks for the getAssociatedStylesheet method
|
||||
* of TransformerFactory.
|
||||
|
@ -0,0 +1,20 @@
|
||||
<?xml version="1.0"?>
|
||||
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
|
||||
<xsl:template match="dataentry">
|
||||
<table cellspacing="0" cellpadding="0" width="85%" align="center"
|
||||
class="color1" border="0">
|
||||
<xsl:apply-templates/>
|
||||
</table>
|
||||
|
||||
</xsl:template>
|
||||
<xsl:template match="list">
|
||||
<xsl:value-of select="self::node()[@multi='false']"/>
|
||||
|
||||
<!--
|
||||
<xsl:if test="self::node()[@multi='false']">
|
||||
<xsl:if test="self::node()">
|
||||
FALSE<br/>
|
||||
</xsl:if>
|
||||
-->
|
||||
</xsl:template>
|
||||
</xsl:stylesheet>
|
@ -0,0 +1,8 @@
|
||||
<appcapp>
|
||||
<dataentry>
|
||||
<list multi="false">
|
||||
<name>TypeOfLifeApp</name>
|
||||
</list>
|
||||
</dataentry>
|
||||
</appcapp>
|
||||
|
@ -46,6 +46,8 @@ import javax.xml.transform.stream.StreamSource;
|
||||
import javax.xml.validation.Schema;
|
||||
import javax.xml.validation.SchemaFactory;
|
||||
|
||||
import jaxp.library.JAXPDataProvider;
|
||||
|
||||
import org.testng.annotations.BeforeClass;
|
||||
import org.testng.annotations.DataProvider;
|
||||
import org.testng.annotations.Test;
|
||||
@ -81,6 +83,59 @@ public class SchemaFactoryTest {
|
||||
xml = Files.readAllBytes(Paths.get(XML_DIR + "test.xml"));
|
||||
}
|
||||
|
||||
|
||||
@DataProvider(name = "parameters")
|
||||
public Object[][] getValidateParameters() {
|
||||
return new Object[][] { { W3C_XML_SCHEMA_NS_URI, SCHEMA_FACTORY_CLASSNAME, null },
|
||||
{ W3C_XML_SCHEMA_NS_URI, SCHEMA_FACTORY_CLASSNAME, this.getClass().getClassLoader() } };
|
||||
}
|
||||
|
||||
/*
|
||||
* test for SchemaFactory.newInstance(java.lang.String schemaLanguage,
|
||||
* java.lang.String factoryClassName, java.lang.ClassLoader classLoader)
|
||||
* factoryClassName points to correct implementation of
|
||||
* javax.xml.validation.SchemaFactory , should return newInstance of
|
||||
* SchemaFactory
|
||||
*/
|
||||
@Test(dataProvider = "parameters")
|
||||
public void testNewInstance(String schemaLanguage, String factoryClassName, ClassLoader classLoader) throws SAXException {
|
||||
SchemaFactory sf = SchemaFactory.newInstance(W3C_XML_SCHEMA_NS_URI, SCHEMA_FACTORY_CLASSNAME, null);
|
||||
Schema schema = sf.newSchema();
|
||||
assertNotNull(schema);
|
||||
}
|
||||
|
||||
/*
|
||||
* test for SchemaFactory.newInstance(java.lang.String schemaLanguage,
|
||||
* java.lang.String factoryClassName, java.lang.ClassLoader classLoader)
|
||||
* factoryClassName is null , should throw IllegalArgumentException
|
||||
*/
|
||||
@Test(expectedExceptions = IllegalArgumentException.class, dataProvider = "new-instance-neg", dataProviderClass = JAXPDataProvider.class)
|
||||
public void testNewInstanceWithNullFactoryClassName(String factoryClassName, ClassLoader classLoader) {
|
||||
|
||||
SchemaFactory.newInstance(W3C_XML_SCHEMA_NS_URI, factoryClassName, classLoader);
|
||||
}
|
||||
|
||||
/*
|
||||
* test for SchemaFactory.newInstance(java.lang.String schemaLanguage,
|
||||
* java.lang.String factoryClassName, java.lang.ClassLoader classLoader)
|
||||
* schemaLanguage is null , should throw NPE
|
||||
*/
|
||||
@Test(expectedExceptions = NullPointerException.class)
|
||||
public void testNewInstanceWithNullSchemaLanguage() {
|
||||
SchemaFactory.newInstance(null, SCHEMA_FACTORY_CLASSNAME, this.getClass().getClassLoader());
|
||||
}
|
||||
|
||||
/*
|
||||
* test for SchemaFactory.newInstance(java.lang.String schemaLanguage,
|
||||
* java.lang.String factoryClassName, java.lang.ClassLoader classLoader)
|
||||
* schemaLanguage is empty , should throw IllegalArgumentException
|
||||
*/
|
||||
@Test(expectedExceptions = IllegalArgumentException.class)
|
||||
public void testNewInstanceWithEmptySchemaLanguage() {
|
||||
SchemaFactory.newInstance("", SCHEMA_FACTORY_CLASSNAME, this.getClass().getClassLoader());
|
||||
}
|
||||
|
||||
|
||||
@Test(expectedExceptions = SAXParseException.class)
|
||||
public void testNewSchemaDefault() throws SAXException, IOException {
|
||||
validate(sf.newSchema());
|
||||
@ -288,6 +343,8 @@ public class SchemaFactoryTest {
|
||||
|
||||
private static final String UNRECOGNIZED_NAME = "http://xml.org/sax/features/namespace-prefixes";
|
||||
|
||||
private static final String SCHEMA_FACTORY_CLASSNAME = "com.sun.org.apache.xerces.internal.jaxp.validation.XMLSchemaFactory";
|
||||
|
||||
private SchemaFactory sf;
|
||||
private byte[] xsd1;
|
||||
private byte[] xsd2;
|
||||
|
@ -24,10 +24,16 @@
|
||||
package javax.xml.xpath.ptests;
|
||||
|
||||
import static javax.xml.xpath.XPathConstants.DOM_OBJECT_MODEL;
|
||||
|
||||
import javax.xml.xpath.XPath;
|
||||
import javax.xml.xpath.XPathFactory;
|
||||
import javax.xml.xpath.XPathFactoryConfigurationException;
|
||||
|
||||
import jaxp.library.JAXPDataProvider;
|
||||
import jaxp.library.JAXPBaseTest;
|
||||
import static org.testng.AssertJUnit.assertNotNull;
|
||||
import static org.testng.Assert.assertNotNull;
|
||||
|
||||
import org.testng.annotations.DataProvider;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
/**
|
||||
@ -44,6 +50,78 @@ public class XPathFactoryTest extends JAXPBaseTest {
|
||||
*/
|
||||
private static final String INVALID_URL = "http://java.sun.com/jaxp/xpath/dom1";
|
||||
|
||||
/**
|
||||
* XPathFactory implementation class name.
|
||||
*/
|
||||
private static final String XPATH_FACTORY_CLASSNAME = "com.sun.org.apache.xpath.internal.jaxp.XPathFactoryImpl";
|
||||
|
||||
|
||||
/**
|
||||
* Provide valid XPathFactory instantiation parameters.
|
||||
*
|
||||
* @return a data provider contains XPathFactory instantiation parameters.
|
||||
*/
|
||||
@DataProvider(name = "parameters")
|
||||
public Object[][] getValidateParameters() {
|
||||
return new Object[][] { { VALID_URL, XPATH_FACTORY_CLASSNAME, null }, { VALID_URL, XPATH_FACTORY_CLASSNAME, this.getClass().getClassLoader() } };
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for XPathFactory.newInstance(java.lang.String uri, java.lang.String
|
||||
* factoryClassName, java.lang.ClassLoader classLoader) factoryClassName
|
||||
* points to correct implementation of javax.xml.xpath.XPathFactory , should
|
||||
* return newInstance of XPathFactory
|
||||
*
|
||||
* @param uri
|
||||
* @param factoryClassName
|
||||
* @param classLoader
|
||||
* @throws XPathFactoryConfigurationException
|
||||
*/
|
||||
@Test(dataProvider = "parameters")
|
||||
public void testNewInstance(String uri, String factoryClassName, ClassLoader classLoader) throws XPathFactoryConfigurationException {
|
||||
XPathFactory xpf = XPathFactory.newInstance(uri, factoryClassName, classLoader);
|
||||
XPath xpath = xpf.newXPath();
|
||||
assertNotNull(xpath);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for XPathFactory.newInstance(java.lang.String uri, java.lang.String
|
||||
* factoryClassName, java.lang.ClassLoader classLoader)
|
||||
*
|
||||
* @param factoryClassName
|
||||
* @param classLoader
|
||||
* @throws XPathFactoryConfigurationException
|
||||
* is expected when factoryClassName is null
|
||||
*/
|
||||
@Test(expectedExceptions = XPathFactoryConfigurationException.class, dataProvider = "new-instance-neg", dataProviderClass = JAXPDataProvider.class)
|
||||
public void testNewInstanceWithNullFactoryClassName(String factoryClassName, ClassLoader classLoader) throws XPathFactoryConfigurationException {
|
||||
XPathFactory.newInstance(VALID_URL, factoryClassName, classLoader);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for XPathFactory.newInstance(java.lang.String uri, java.lang.String
|
||||
* factoryClassName, java.lang.ClassLoader classLoader) uri is null , should
|
||||
* throw NPE
|
||||
*
|
||||
* @throws XPathFactoryConfigurationException
|
||||
*/
|
||||
@Test(expectedExceptions = NullPointerException.class)
|
||||
public void testNewInstanceWithNullUri() throws XPathFactoryConfigurationException {
|
||||
XPathFactory.newInstance(null, XPATH_FACTORY_CLASSNAME, this.getClass().getClassLoader());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for XPathFactory.newInstance(java.lang.String uri, java.lang.String
|
||||
* factoryClassName, java.lang.ClassLoader classLoader)
|
||||
*
|
||||
* @throws IllegalArgumentException
|
||||
* is expected when uri is empty
|
||||
*/
|
||||
@Test(expectedExceptions = IllegalArgumentException.class)
|
||||
public void testNewInstanceWithEmptyUri() throws XPathFactoryConfigurationException {
|
||||
XPathFactory.newInstance("", XPATH_FACTORY_CLASSNAME, this.getClass().getClassLoader());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for constructor - XPathFactory.newInstance().
|
||||
*/
|
||||
|
@ -0,0 +1,38 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package jaxp.library;
|
||||
|
||||
import org.testng.annotations.DataProvider;
|
||||
|
||||
/**
|
||||
* Provide invalid parameters for negative testing Factory.newInstance.
|
||||
*/
|
||||
public class JAXPDataProvider {
|
||||
|
||||
@DataProvider(name = "new-instance-neg")
|
||||
public static Object[][] getNewInstanceNeg() {
|
||||
return new Object[][] { { null, null }, { null, JAXPDataProvider.class.getClassLoader() } };
|
||||
}
|
||||
|
||||
}
|
@ -291,3 +291,4 @@ e336cbd8b15e959e70ed02f0f5e93fa76ebd4c07 jdk9-b41
|
||||
efedac7f44ed41cea2b1038138047271f55aacba jdk9-b46
|
||||
b641c14730ac05d9ec8b4f66e6fca3dc21adb403 jdk9-b47
|
||||
ebb2eb7f1aec78eb6d8cc4c96f018afa11093cde jdk9-b48
|
||||
541a8cef4e0d54c3e4b52a98c6af3c31e2096669 jdk9-b49
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user