This commit is contained in:
Lana Steuck 2017-02-23 17:57:07 +00:00
commit a6733656e4
94 changed files with 1402 additions and 2346 deletions

View File

@ -399,3 +399,4 @@ d7034ff7f8e257e81c9f95c7785dd4eaaa3c2afc jdk-9+153
8c70d170e62c0c58b5bc3ba666bd140399b98c9c jdk-10+0
45b751afd11e6c05991cf4913c5a0ac3304fcc4e jdk-9+154
f4aff695ffe05cfdb69d8af25a4ddc6a029754ea jdk-9+155
06bce0388880b5ff8e040e4a9d72a3ea11dac321 jdk-9+156

View File

@ -396,5 +396,7 @@ b119012d1c2ab2570fe8718633840d0c1f1f441d jdk-9+149
71a766d4c18041a7f833ee22823125b02e1a7f1e jdk-9+151
ef056360ddf3977d7d2ddbeb456a4d612d19ea05 jdk-9+152
816a6d03a7c44edfbd8780110529f1bdc3964fb9 jdk-9+153
8d22611ffb6540bc1ace64a00c048c8b82d8c69a jdk-10+0
8d26916eaa21b689835ffc1c0dbf12470aa9be61 jdk-9+154
688a3863c00ebc089ab17ee1fc46272cbbd96815 jdk-9+155
783ec7542cf7154e5d2b87f55bb97d28f81e9ada jdk-9+156

View File

@ -1 +1 @@
project=jdk9
project=jdk10

View File

@ -1,5 +1,5 @@
#
# Copyright (c) 2011, 2016, Oracle and/or its affiliates. All rights reserved.
# Copyright (c) 2011, 2017, 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
@ -25,7 +25,7 @@
# Default version numbers to use unless overridden by configure
DEFAULT_VERSION_MAJOR=9
DEFAULT_VERSION_MAJOR=10
DEFAULT_VERSION_MINOR=0
DEFAULT_VERSION_SECURITY=0
DEFAULT_VERSION_PATCH=0

View File

@ -1080,7 +1080,7 @@ var getVersion = function (major, minor, security, patch) {
+ "." + (minor != null ? minor : version_numbers.get("DEFAULT_VERSION_MINOR"))
+ "." + (security != null ? security : version_numbers.get("DEFAULT_VERSION_SECURITY"))
+ "." + (patch != null ? patch : version_numbers.get("DEFAULT_VERSION_PATCH"));
while (version.match(".*\.0$")) {
while (version.match(".*\\.0$")) {
version = version.substring(0, version.length - 2);
}
return version;

View File

@ -396,5 +396,7 @@ f95cc86b6ac22ec1ade5d4f825dc7782adeea228 jdk-9+148
77f827f5bbad3ef795664bc675f72d98d156b9f8 jdk-9+151
ff8cb43c07c069b1debdee44cb88ca22db1ec757 jdk-9+152
68a8e8658511093b322a46ed04b2a321e1da2a43 jdk-9+153
d66f97a610a6beac987740edc2bf6a70f46ba574 jdk-10+0
078ebe23b584466dc8346e620d7821d91751e5a9 jdk-9+154
a545f54babfa31aa7eb611f36031609acd617cbc jdk-9+155
907c26240cd481579e919bfd23740797ff8ce1c8 jdk-9+156

View File

@ -1 +1 @@
project=jdk9
project=jdk10

View File

@ -556,5 +556,7 @@ a82cb5350cad96a0b4de496afebe3ded89f27efa jdk-9+146
2a2ac7d9f52c8cb2b80077e515b5840b947e640c jdk-9+151
31f1d26c60df7b2e516a4f84160d76ba017d4e09 jdk-9+152
217ba81b9a4ce8698200370175aa2db86a39f66c jdk-9+153
fc7e94cb748507366b839e859f865f724467446a jdk-10+0
a9fdfd55835ef9dccb7f317b07249bd66653b874 jdk-9+154
f3b3d77a1751897413aae43ac340a130b6fa2ae1 jdk-9+155
43139c588ea48b6504e52b6c3dec530b17b1fdb4 jdk-9+156

View File

@ -1 +1 @@
project=jdk9
project=jdk10

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2014, Red Hat Inc. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
@ -45,10 +45,8 @@ define_pd_global(bool, TieredCompilation, false);
// We compile very aggressively with the builtin simulator because
// doing so greatly reduces run times and tests more code.
define_pd_global(intx, CompileThreshold, 150 );
define_pd_global(intx, BackEdgeThreshold, 500);
#else
define_pd_global(intx, CompileThreshold, 1500 );
define_pd_global(intx, BackEdgeThreshold, 100000);
#endif
define_pd_global(intx, OnStackReplacePercentage, 933 );
@ -76,6 +74,4 @@ define_pd_global(bool, OptimizeSinglePrecision, true );
define_pd_global(bool, CSEArrayLength, false);
define_pd_global(bool, TwoOperandLIRForm, false );
define_pd_global(intx, SafepointPollOffset, 0 );
#endif // CPU_AARCH64_VM_C1_GLOBALS_AARCH64_HPP

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2014, Red Hat Inc. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
@ -43,7 +43,6 @@ define_pd_global(bool, UseOnStackReplacement, true);
define_pd_global(bool, ProfileInterpreter, true);
define_pd_global(bool, TieredCompilation, trueInTiered);
define_pd_global(intx, CompileThreshold, 10000);
define_pd_global(intx, BackEdgeThreshold, 100000);
define_pd_global(intx, OnStackReplacePercentage, 140);
define_pd_global(intx, ConditionalMoveLimit, 3);

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2003, 2015, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2003, 2017, 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
@ -150,13 +150,7 @@ public class HeapSummary extends Tool {
// Helper methods
private void printGCAlgorithm(Map flagMap) {
// print about new generation
long l = getFlagValue("UseParNewGC", flagMap);
if (l == 1L) {
System.out.println("using parallel threads in the new generation.");
}
l = getFlagValue("UseTLAB", flagMap);
long l = getFlagValue("UseTLAB", flagMap);
if (l == 1L) {
System.out.println("using thread-local object allocation.");
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1997, 2017, 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
@ -3050,15 +3050,12 @@ void os::naked_yield() {
thr_yield();
}
// Interface for setting lwp priorities. If we are using T2 libthread,
// which forces the use of BoundThreads or we manually set UseBoundThreads,
// all of our threads will be assigned to real lwp's. Using the thr_setprio
// function is meaningless in this mode so we must adjust the real lwp's priority
// Interface for setting lwp priorities. We are using T2 libthread,
// which forces the use of bound threads, so all of our threads will
// be assigned to real lwp's. Using the thr_setprio function is
// meaningless in this mode so we must adjust the real lwp's priority.
// The routines below implement the getting and setting of lwp priorities.
//
// Note: T2 is now the only supported libthread. UseBoundThreads flag is
// being deprecated and all threads are now BoundThreads
//
// Note: There are three priority scales used on Solaris. Java priotities
// which range from 1 to 10, libthread "thr_setprio" scale which range
// from 0 to 127, and the current scheduling class of the process we

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2001, 2016, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2001, 2017, 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
@ -488,9 +488,6 @@ CMSCollector::CMSCollector(ConcurrentMarkSweepGeneration* cmsGen,
_gc_timer_cm(new (ResourceObj::C_HEAP, mtGC) ConcurrentGCTimer()),
_cms_start_registered(false)
{
if (ExplicitGCInvokesConcurrentAndUnloadsClasses) {
ExplicitGCInvokesConcurrent = true;
}
// Now expand the span and allocate the collection support structures
// (MUT, marking bit map etc.) to cover both generations subject to
// collection.
@ -2559,10 +2556,8 @@ void CMSCollector::verify_overflow_empty() const {
// Decide if we want to enable class unloading as part of the
// ensuing concurrent GC cycle. We will collect and
// unload classes if it's the case that:
// (1) an explicit gc request has been made and the flag
// ExplicitGCInvokesConcurrentAndUnloadsClasses is set, OR
// (2) (a) class unloading is enabled at the command line, and
// (b) old gen is getting really full
// (a) class unloading is enabled at the command line, and
// (b) old gen is getting really full
// NOTE: Provided there is no change in the state of the heap between
// calls to this method, it should have idempotent results. Moreover,
// its results should be monotonically increasing (i.e. going from 0 to 1,
@ -2575,11 +2570,7 @@ void CMSCollector::verify_overflow_empty() const {
// below.
void CMSCollector::update_should_unload_classes() {
_should_unload_classes = false;
// Condition 1 above
if (_full_gc_requested && ExplicitGCInvokesConcurrentAndUnloadsClasses) {
_should_unload_classes = true;
} else if (CMSClassUnloadingEnabled) { // Condition 2.a above
// Disjuncts 2.b.(i,ii,iii) above
if (CMSClassUnloadingEnabled) {
_should_unload_classes = (concurrent_cycles_since_last_unload() >=
CMSClassUnloadingMaxInterval)
|| _cmsGen->is_too_full();

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1997, 2017, 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
@ -2199,7 +2199,6 @@ void Method::print_on(outputStream* st) const {
ResourceMark rm;
assert(is_method(), "must be method");
st->print_cr("%s", internal_name());
// get the effect of PrintOopAddress, always, for methods:
st->print_cr(" - this oop: " INTPTR_FORMAT, p2i(this));
st->print (" - method holder: "); method_holder()->print_value_on(st); st->cr();
st->print (" - constants: " INTPTR_FORMAT " ", p2i(constants()));

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1997, 2017, 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
@ -2967,14 +2967,7 @@ JVM_ENTRY(void, JVM_Yield(JNIEnv *env, jclass threadClass))
JVMWrapper("JVM_Yield");
if (os::dont_yield()) return;
HOTSPOT_THREAD_YIELD();
// When ConvertYieldToSleep is off (default), this matches the classic VM use of yield.
// Critical for similar threading behaviour
if (ConvertYieldToSleep) {
os::sleep(thread, MinSleepInterval, false);
} else {
os::naked_yield();
}
os::naked_yield();
JVM_END
@ -2998,18 +2991,7 @@ JVM_ENTRY(void, JVM_Sleep(JNIEnv* env, jclass threadClass, jlong millis))
EventThreadSleep event;
if (millis == 0) {
// When ConvertSleepToYield is on, this matches the classic VM implementation of
// JVM_Sleep. Critical for similar threading behaviour (Win32)
// It appears that in certain GUI contexts, it may be beneficial to do a short sleep
// for SOLARIS
if (ConvertSleepToYield) {
os::naked_yield();
} else {
ThreadState old_state = thread->osthread()->get_state();
thread->osthread()->set_state(SLEEPING);
os::sleep(thread, MinSleepInterval, false);
thread->osthread()->set_state(old_state);
}
os::naked_yield();
} else {
ThreadState old_state = thread->osthread()->get_state();
thread->osthread()->set_state(SLEEPING);

View File

@ -375,53 +375,17 @@ static SpecialFlag const special_jvm_flags[] = {
// -------------- Deprecated Flags --------------
// --- Non-alias flags - sorted by obsolete_in then expired_in:
{ "MaxGCMinorPauseMillis", JDK_Version::jdk(8), JDK_Version::undefined(), JDK_Version::undefined() },
{ "AutoGCSelectPauseMillis", JDK_Version::jdk(9), JDK_Version::undefined(), JDK_Version::jdk(10) },
{ "UseAutoGCSelectPolicy", JDK_Version::jdk(9), JDK_Version::undefined(), JDK_Version::jdk(10) },
{ "UseParNewGC", JDK_Version::jdk(9), JDK_Version::undefined(), JDK_Version::jdk(10) },
{ "ExplicitGCInvokesConcurrentAndUnloadsClasses", JDK_Version::jdk(9), JDK_Version::undefined(), JDK_Version::jdk(10) },
{ "ConvertSleepToYield", JDK_Version::jdk(9), JDK_Version::jdk(10), JDK_Version::jdk(11) },
{ "ConvertYieldToSleep", JDK_Version::jdk(9), JDK_Version::jdk(10), JDK_Version::jdk(11) },
// --- Deprecated alias flags (see also aliased_jvm_flags) - sorted by obsolete_in then expired_in:
{ "DefaultMaxRAMFraction", JDK_Version::jdk(8), JDK_Version::undefined(), JDK_Version::undefined() },
{ "CreateMinidumpOnCrash", JDK_Version::jdk(9), JDK_Version::undefined(), JDK_Version::undefined() },
{ "CMSMarkStackSizeMax", JDK_Version::jdk(9), JDK_Version::undefined(), JDK_Version::jdk(10) },
{ "CMSMarkStackSize", JDK_Version::jdk(9), JDK_Version::undefined(), JDK_Version::jdk(10) },
{ "G1MarkStackSize", JDK_Version::jdk(9), JDK_Version::undefined(), JDK_Version::jdk(10) },
{ "ParallelMarkingThreads", JDK_Version::jdk(9), JDK_Version::undefined(), JDK_Version::jdk(10) },
{ "ParallelCMSThreads", JDK_Version::jdk(9), JDK_Version::undefined(), JDK_Version::jdk(10) },
// -------------- Obsolete Flags - sorted by expired_in --------------
{ "UseOldInlining", JDK_Version::undefined(), JDK_Version::jdk(9), JDK_Version::jdk(10) },
{ "SafepointPollOffset", JDK_Version::undefined(), JDK_Version::jdk(9), JDK_Version::jdk(10) },
{ "UseBoundThreads", JDK_Version::undefined(), JDK_Version::jdk(9), JDK_Version::jdk(10) },
{ "DefaultThreadPriority", JDK_Version::undefined(), JDK_Version::jdk(9), JDK_Version::jdk(10) },
{ "NoYieldsInMicrolock", JDK_Version::undefined(), JDK_Version::jdk(9), JDK_Version::jdk(10) },
{ "BackEdgeThreshold", JDK_Version::undefined(), JDK_Version::jdk(9), JDK_Version::jdk(10) },
{ "UseNewReflection", JDK_Version::undefined(), JDK_Version::jdk(9), JDK_Version::jdk(10) },
{ "ReflectionWrapResolutionErrors",JDK_Version::undefined(), JDK_Version::jdk(9), JDK_Version::jdk(10) },
{ "VerifyReflectionBytecodes", JDK_Version::undefined(), JDK_Version::jdk(9), JDK_Version::jdk(10) },
{ "AutoShutdownNMT", JDK_Version::undefined(), JDK_Version::jdk(9), JDK_Version::jdk(10) },
{ "NmethodSweepFraction", JDK_Version::undefined(), JDK_Version::jdk(9), JDK_Version::jdk(10) },
{ "NmethodSweepCheckInterval", JDK_Version::undefined(), JDK_Version::jdk(9), JDK_Version::jdk(10) },
{ "CodeCacheMinimumFreeSpace", JDK_Version::undefined(), JDK_Version::jdk(9), JDK_Version::jdk(10) },
#ifndef ZERO
{ "UseFastAccessorMethods", JDK_Version::undefined(), JDK_Version::jdk(9), JDK_Version::jdk(10) },
{ "UseFastEmptyMethods", JDK_Version::undefined(), JDK_Version::jdk(9), JDK_Version::jdk(10) },
#endif // ZERO
{ "UseCompilerSafepoints", JDK_Version::undefined(), JDK_Version::jdk(9), JDK_Version::jdk(10) },
{ "AdaptiveSizePausePolicy", JDK_Version::undefined(), JDK_Version::jdk(9), JDK_Version::jdk(10) },
{ "ParallelGCRetainPLAB", JDK_Version::undefined(), JDK_Version::jdk(9), JDK_Version::jdk(10) },
{ "ThreadSafetyMargin", JDK_Version::undefined(), JDK_Version::jdk(9), JDK_Version::jdk(10) },
{ "LazyBootClassLoader", JDK_Version::undefined(), JDK_Version::jdk(9), JDK_Version::jdk(10) },
{ "StarvationMonitorInterval", JDK_Version::undefined(), JDK_Version::jdk(9), JDK_Version::jdk(10) },
{ "PreInflateSpin", JDK_Version::undefined(), JDK_Version::jdk(9), JDK_Version::jdk(10) },
{ "JNIDetachReleasesMonitors", JDK_Version::undefined(), JDK_Version::jdk(9), JDK_Version::jdk(10) },
{ "UseAltSigs", JDK_Version::undefined(), JDK_Version::jdk(9), JDK_Version::jdk(10) },
{ "SegmentedHeapDumpThreshold", JDK_Version::undefined(), JDK_Version::jdk(9), JDK_Version::jdk(10) },
{ "PrintOopAddress", JDK_Version::undefined(), JDK_Version::jdk(9), JDK_Version::jdk(10) },
{ "PermSize", JDK_Version::undefined(), JDK_Version::jdk(8), JDK_Version::jdk(10) },
{ "MaxPermSize", JDK_Version::undefined(), JDK_Version::jdk(8), JDK_Version::jdk(10) },
{ "ConvertSleepToYield", JDK_Version::jdk(9), JDK_Version::jdk(10), JDK_Version::jdk(11) },
{ "ConvertYieldToSleep", JDK_Version::jdk(9), JDK_Version::jdk(10), JDK_Version::jdk(11) },
{ "MinSleepInterval", JDK_Version::jdk(9), JDK_Version::jdk(10), JDK_Version::jdk(11) },
{ "PermSize", JDK_Version::undefined(), JDK_Version::jdk(8), JDK_Version::undefined() },
{ "MaxPermSize", JDK_Version::undefined(), JDK_Version::jdk(8), JDK_Version::undefined() },
#ifdef TEST_VERIFY_SPECIAL_JVM_FLAGS
{ "dep > obs", JDK_Version::jdk(9), JDK_Version::jdk(8), JDK_Version::undefined() },
@ -444,11 +408,6 @@ typedef struct {
static AliasedFlag const aliased_jvm_flags[] = {
{ "DefaultMaxRAMFraction", "MaxRAMFraction" },
{ "CMSMarkStackSizeMax", "MarkStackSizeMax" },
{ "CMSMarkStackSize", "MarkStackSize" },
{ "G1MarkStackSize", "MarkStackSize" },
{ "ParallelMarkingThreads", "ConcGCThreads" },
{ "ParallelCMSThreads", "ConcGCThreads" },
{ "CreateMinidumpOnCrash", "CreateCoredumpOnCrash" },
{ NULL, NULL}
};
@ -1547,7 +1506,6 @@ void Arguments::set_parnew_gc_flags() {
assert(!UseSerialGC && !UseParallelOldGC && !UseParallelGC && !UseG1GC,
"control point invariant");
assert(UseConcMarkSweepGC, "CMS is expected to be on here");
assert(UseParNewGC, "ParNew should always be used with CMS");
if (FLAG_IS_DEFAULT(ParallelGCThreads)) {
FLAG_SET_DEFAULT(ParallelGCThreads, Abstract_VM_Version::parallel_worker_threads());
@ -1588,7 +1546,6 @@ void Arguments::set_parnew_gc_flags() {
void Arguments::set_cms_and_parnew_gc_flags() {
assert(!UseSerialGC && !UseParallelOldGC && !UseParallelGC, "Error");
assert(UseConcMarkSweepGC, "CMS is expected to be on here");
assert(UseParNewGC, "ParNew should always be used with CMS");
// Turn off AdaptiveSizePolicy by default for cms until it is complete.
disable_adaptive_size_policy("UseConcMarkSweepGC");
@ -1728,16 +1685,6 @@ size_t Arguments::max_heap_for_compressed_oops() {
NOT_LP64(ShouldNotReachHere(); return 0);
}
bool Arguments::should_auto_select_low_pause_collector() {
if (UseAutoGCSelectPolicy &&
!FLAG_IS_DEFAULT(MaxGCPauseMillis) &&
(MaxGCPauseMillis <= AutoGCSelectPauseMillis)) {
log_trace(gc)("Automatic selection of the low pause collector based on pause goal of %d (ms)", (int) MaxGCPauseMillis);
return true;
}
return false;
}
void Arguments::set_use_compressed_oops() {
#ifndef ZERO
#ifdef _LP64
@ -1841,16 +1788,7 @@ void Arguments::select_compilation_mode_ergonomically() {
void Arguments::select_gc_ergonomically() {
#if INCLUDE_ALL_GCS
if (os::is_server_class_machine()) {
if (!UseAutoGCSelectPolicy) {
FLAG_SET_ERGO_IF_DEFAULT(bool, UseG1GC, true);
} else {
if (should_auto_select_low_pause_collector()) {
FLAG_SET_ERGO_IF_DEFAULT(bool, UseConcMarkSweepGC, true);
FLAG_SET_ERGO_IF_DEFAULT(bool, UseParNewGC, true);
} else {
FLAG_SET_ERGO_IF_DEFAULT(bool, UseParallelGC, true);
}
}
FLAG_SET_ERGO_IF_DEFAULT(bool, UseG1GC, true);
} else {
FLAG_SET_ERGO_IF_DEFAULT(bool, UseSerialGC, true);
}
@ -1859,7 +1797,6 @@ void Arguments::select_gc_ergonomically() {
UNSUPPORTED_OPTION(UseParallelGC);
UNSUPPORTED_OPTION(UseParallelOldGC);
UNSUPPORTED_OPTION(UseConcMarkSweepGC);
UNSUPPORTED_OPTION(UseParNewGC);
FLAG_SET_ERGO_IF_DEFAULT(bool, UseSerialGC, true);
#endif // INCLUDE_ALL_GCS
}
@ -2073,7 +2010,6 @@ void Arguments::set_gc_specific_flags() {
if (!ClassUnloading) {
FLAG_SET_CMDLINE(bool, CMSClassUnloadingEnabled, false);
FLAG_SET_CMDLINE(bool, ClassUnloadingWithConcurrentMark, false);
FLAG_SET_CMDLINE(bool, ExplicitGCInvokesConcurrentAndUnloadsClasses, false);
}
#endif // INCLUDE_ALL_GCS
}
@ -2428,18 +2364,6 @@ bool Arguments::check_gc_consistency() {
return false;
}
if (UseConcMarkSweepGC && !UseParNewGC) {
jio_fprintf(defaultStream::error_stream(),
"It is not possible to combine the DefNew young collector with the CMS collector.\n");
return false;
}
if (UseParNewGC && !UseConcMarkSweepGC) {
jio_fprintf(defaultStream::error_stream(),
"It is not possible to combine the ParNew young collector with any collector other than CMS.\n");
return false;
}
return true;
}
@ -3726,11 +3650,6 @@ jint Arguments::finalize_vm_init_args() {
}
}
if (UseConcMarkSweepGC && FLAG_IS_DEFAULT(UseParNewGC) && !UseParNewGC) {
// CMS can only be used with ParNew
FLAG_SET_ERGO(bool, UseParNewGC, true);
}
if (!check_vm_args_consistency()) {
return JNI_ERR;
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1997, 2017, 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
@ -480,9 +480,6 @@ class Arguments : AllStatic {
static julong limit_by_allocatable_memory(julong size);
// Setup heap size
static void set_heap_size();
// Based on automatic selection criteria, should the
// low pause collector be used.
static bool should_auto_select_low_pause_collector();
// Bytecode rewriting
static void set_bytecode_flags();

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1997, 2017, 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
@ -1159,13 +1159,6 @@ public:
product_pd(bool, DontYieldALot, \
"Throw away obvious excess yield calls") \
\
product(bool, ConvertSleepToYield, true, \
"Convert sleep(0) to thread yield ") \
\
product(bool, ConvertYieldToSleep, false, \
"Convert yield to a sleep of MinSleepInterval to simulate Win32 " \
"behavior") \
\
develop(bool, UseDetachedThreads, true, \
"Use detached threads that are recycled upon termination " \
"(for Solaris only)") \
@ -1479,11 +1472,6 @@ public:
"A System.gc() request invokes a concurrent collection; " \
"(effective only when using concurrent collectors)") \
\
product(bool, ExplicitGCInvokesConcurrentAndUnloadsClasses, false, \
"A System.gc() request invokes a concurrent collection and " \
"also unloads classes during such a concurrent gc cycle " \
"(effective only when UseConcMarkSweepGC)") \
\
product(bool, GCLockerInvokesConcurrent, false, \
"The exit of a JNI critical section necessitating a scavenge, " \
"also kicks off a background concurrent collection") \
@ -1501,9 +1489,6 @@ public:
product(bool, UseCMSBestFit, true, \
"Use CMS best fit allocation strategy") \
\
product(bool, UseParNewGC, false, \
"Use parallel threads in the new generation") \
\
product(uintx, ParallelGCBufferWastePct, 10, \
"Wasted fraction of parallel allocation buffer") \
range(0, 100) \
@ -2059,13 +2044,6 @@ public:
"Maximum fraction (1/n) of virtual memory used for ergonomically "\
"determining maximum heap size") \
\
product(bool, UseAutoGCSelectPolicy, false, \
"Use automatic collection selection policy") \
\
product(uintx, AutoGCSelectPauseMillis, 5000, \
"Automatic GC selection pause threshold in milliseconds") \
range(0, max_uintx) \
\
product(bool, UseAdaptiveSizePolicy, true, \
"Use adaptive generation sizing policies") \
\
@ -3003,10 +2981,6 @@ public:
develop(intx, DontYieldALotInterval, 10, \
"Interval between which yields will be dropped (milliseconds)") \
\
develop(intx, MinSleepInterval, 1, \
"Minimum sleep() interval (milliseconds) when " \
"ConvertSleepToYield is off (used for Solaris)") \
\
develop(intx, ProfilerPCTickThreshold, 15, \
"Number of ticks in a PC buckets to be a hotspot") \
\

View File

@ -1,5 +1,5 @@
#
# Copyright (c) 2013, 2016, Oracle and/or its affiliates. All rights reserved.
# Copyright (c) 2013, 2017, 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
@ -209,11 +209,8 @@ needs_full_vm_compact1 = \
gc/g1/TestShrinkToOneRegion.java \
gc/metaspace/G1AddMetaspaceDependency.java \
gc/startup_warnings/TestCMS.java \
gc/startup_warnings/TestDefNewCMS.java \
gc/startup_warnings/TestParallelGC.java \
gc/startup_warnings/TestParallelScavengeSerialOld.java \
gc/startup_warnings/TestParNewCMS.java \
gc/startup_warnings/TestParNewSerialOld.java \
runtime/SharedArchiveFile/SharedArchiveFile.java
# Minimal VM on Compact 2 adds in some compact2 tests

View File

@ -1,48 +0,0 @@
/*
* Copyright (c) 2016, 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 TestExplicitGCInvokesConcurrentAndUnloadsClasses
* @summary Test that the flag ExplicitGCInvokesConcurrentAndUnloadsClasses is deprecated
* @bug 8170388
* @key gc
* @library /test/lib
* @modules java.base/jdk.internal.misc
* java.management
* @run driver TestExplicitGCInvokesConcurrentAndUnloadsClasses
*/
import jdk.test.lib.process.OutputAnalyzer;
import jdk.test.lib.process.ProcessTools;
public class TestExplicitGCInvokesConcurrentAndUnloadsClasses {
public static void main(String[] args) throws Exception {
ProcessBuilder pb =
ProcessTools.createJavaProcessBuilder("-XX:+ExplicitGCInvokesConcurrentAndUnloadsClasses",
"-Xlog:gc",
"-version");
OutputAnalyzer output = new OutputAnalyzer(pb.start());
output.shouldContain("ExplicitGCInvokesConcurrentAndUnloadsClasses was deprecated");
output.shouldHaveExitValue(0);
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2015, 2017, 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
@ -66,7 +66,6 @@ public class TestSelectDefaultGC {
assertVMOption(output, "UseSerialGC", !isServer);
// CMS is never default
assertVMOption(output, "UseConcMarkSweepGC", false);
assertVMOption(output, "UseParNewGC", false);
}
public static void main(String[] args) throws Exception {

View File

@ -1,48 +0,0 @@
/*
* Copyright (c) 2013, 2016, 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 TestParNewSerialOld
* @key gc
* @bug 8065972
* @summary Test that the unsupported ParNew+SerialOld combination does not start
* @library /test/lib
* @modules java.base/jdk.internal.misc
* java.management
*/
import jdk.test.lib.process.ProcessTools;
import jdk.test.lib.process.OutputAnalyzer;
public class TestParNewSerialOld {
public static void main(String args[]) throws Exception {
ProcessBuilder pb = ProcessTools.createJavaProcessBuilder("-XX:+UseParNewGC", "-version");
OutputAnalyzer output = new OutputAnalyzer(pb.start());
output.shouldContain("It is not possible to combine the ParNew young collector with any collector other than CMS.");
output.shouldContain("Error");
output.shouldHaveExitValue(1);
}
}

View File

@ -1,47 +0,0 @@
/*
* Copyright (c) 2016, 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 TestUseAutoGCSelectPolicy
* @key gc
* @bug 8166461 8167494
* @summary Test that UseAutoGCSelectPolicy and AutoGCSelectPauseMillis do print a warning message
* @library /test/lib
* @modules java.base/jdk.internal.misc
* java.management
*/
import jdk.test.lib.process.ProcessTools;
import jdk.test.lib.process.OutputAnalyzer;
public class TestUseAutoGCSelectPolicy {
public static void main(String args[]) throws Exception {
ProcessBuilder pb = ProcessTools.createJavaProcessBuilder("-XX:+UseAutoGCSelectPolicy", "-XX:AutoGCSelectPauseMillis=3000", "-version");
OutputAnalyzer output = new OutputAnalyzer(pb.start());
output.shouldContain("UseAutoGCSelectPolicy was deprecated in version 9.0");
output.shouldContain("AutoGCSelectPauseMillis was deprecated in version 9.0");
output.shouldNotContain("error");
output.shouldHaveExitValue(0);
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2014, 2017, 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
@ -37,18 +37,18 @@ public class ObsoleteFlagErrorMessage {
// Case 1: Newly obsolete flags with extra junk appended should not be treated as newly obsolete (8060449)
ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
"-XX:UseOldInliningPlusJunk", "-version");
"-XX:ConvertSleepToYieldPlusJunk", "-version");
OutputAnalyzer output = new OutputAnalyzer(pb.start());
output.shouldContain("Unrecognized VM option 'UseOldInliningPlusJunk'"); // Must identify bad option.
output.shouldContain("Unrecognized VM option 'ConvertSleepToYieldPlusJunk'"); // Must identify bad option.
output.shouldHaveExitValue(1);
// Case 2: Newly obsolete integer-valued flags should be recognized as newly obsolete (8073989)
// Case 2: Newly obsolete flags should be recognized as newly obsolete (8073989)
ProcessBuilder pb2 = ProcessTools.createJavaProcessBuilder(
"-XX:NmethodSweepFraction=10", "-version");
"-XX:+ConvertSleepToYield", "-version");
OutputAnalyzer output2 = new OutputAnalyzer(pb2.start());
output2.shouldContain("Ignoring option").shouldContain("support was removed");
output2.shouldContain("NmethodSweepFraction");
output2.shouldContain("ConvertSleepToYield");
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2015, 2017, 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
@ -40,11 +40,6 @@ public class VMAliasOptions {
*/
public static final String[][] ALIAS_OPTIONS = {
{"DefaultMaxRAMFraction", "MaxRAMFraction", "1032"},
{"CMSMarkStackSizeMax", "MarkStackSizeMax", "1032"},
{"CMSMarkStackSize", "MarkStackSize", "1032"},
{"G1MarkStackSize", "MarkStackSize", "1032"},
{"ParallelMarkingThreads", "ConcGCThreads", "2"},
{"ParallelCMSThreads", "ConcGCThreads", "2"},
{"CreateMinidumpOnCrash", "CreateCoredumpOnCrash", "false" },
};

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2015, 2017, 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
@ -41,17 +41,9 @@ public class VMDeprecatedOptions {
public static final String[][] DEPRECATED_OPTIONS = {
// deprecated non-alias flags:
{"MaxGCMinorPauseMillis", "1032"},
{"UseParNewGC", "false"},
{"ConvertSleepToYield", "false" },
{"ConvertYieldToSleep", "false" },
// deprecated alias flags (see also aliased_jvm_flags):
{"DefaultMaxRAMFraction", "4"},
{"CMSMarkStackSizeMax", "1032"},
{"CMSMarkStackSize", "1032"},
{"G1MarkStackSize", "1032"},
{"ParallelMarkingThreads", "2"},
{"ParallelCMSThreads", "2"},
{"CreateMinidumpOnCrash", "false"}
};

View File

@ -396,5 +396,7 @@ f85154af719f99a3b4d81b67a8b4c18a650d10f9 jdk-9+150
13c6906bfc861d99dc35a19c80b7a99f0b0ac58d jdk-9+151
7e3da313b1746578da648155e37dd8526e83153d jdk-9+152
1384504d2cd0e55c5e0becaeaf40ab05cae959d6 jdk-9+153
0908877116d17c6e59092ec7d53ef687a96d3278 jdk-10+0
7fa738305436d14c0926df0f04892890cacc766b jdk-9+154
48fa77af153288b08ba794e1616a7b0685f3b67e jdk-9+155
e930c373aaa4e0e712c9a25ba4b03d473b48c294 jdk-9+156

View File

@ -1 +1 @@
project=jdk9
project=jdk10

View File

@ -399,5 +399,7 @@ c8c9c334743caf8155c9809b6b4ac315d3a66476 jdk-9+148
c48b4d4768b1c2b8fe5d1a844ca13732e5dfbe2a jdk-9+151
6f8fb1cf7e5f61c40dcc3654f9a623c505f6de1f jdk-9+152
7a532a9a227137155b905341d4b99939db51220e jdk-9+153
34af95c7dbff74f3448fcdb7d745524e8a1cc88a jdk-10+0
34af95c7dbff74f3448fcdb7d745524e8a1cc88a jdk-9+154
9b9918656c97724fd89c04a8547043bbd37f5935 jdk-9+155
7c829eba781409b4fe15392639289af1553dcf63 jdk-9+156

View File

@ -1 +1 @@
project=jdk9
project=jdk10

View File

@ -396,6 +396,7 @@ c41140100bf1e5c10c7b8f3bde91c16eff7485f5 jdk-9+147
d27bab22ff62823902d93d1d35ca397cfd50d059 jdk-9+151
a20f2cf90762673e1bc4980fd6597e70a2578045 jdk-9+152
1c4411322327aea3f91011ec3977a12a05b09629 jdk-9+153
f2325d80b37c2817e15039bf64189a08e29c6d39 jdk-10+0
c97e7a8b8da062b9070df442f9cf308e10845fb7 jdk-9+154
e170c858888e83d5c0994504599b6ed7a1fb0cfc jdk-9+155
7d64e541a6c04c714bcad4c8b553db912f827cd5 jdk-9+156

View File

@ -1 +1 @@
project=jdk9
project=jdk10

View File

@ -1,5 +1,5 @@
#
# Copyright (c) 2011, 2016, Oracle and/or its affiliates. All rights reserved.
# Copyright (c) 2011, 2017, 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,102 +71,37 @@ $(eval $(call SetupBuildLauncher, keytool, \
################################################################################
BUILD_JEXEC :=
BUILD_JEXEC_SRC :=
BUILD_JEXEC_INC :=
BUILD_JEXEC_DST_DIR := $(SUPPORT_OUTPUTDIR)/modules_libs/java.base
#
# UNHANDLED:
# - COMPILE_APPROACH = normal
#
#
# jdk/make/java/Makefile
#
ifeq ($(OPENJDK_TARGET_OS), solaris)
ifeq ($(OPENJDK_TARGET_CPU_BITS), 32)
BUILD_JEXEC := 1
endif
endif
ifeq ($(OPENJDK_TARGET_OS), linux)
BUILD_JEXEC := 1
endif # OPENJDK_TARGET_OS
#
# jdk/make/java/jexec/Makefile
#
ifeq ($(BUILD_JEXEC), 1)
ifeq ($(OPENJDK_TARGET_OS), windows)
else ifeq ($(OPENJDK_TARGET_OS), macosx)
BUILD_JEXEC_SRC := $(JDK_TOPDIR)/src/java.base/macosx/native/launcher
else
BUILD_JEXEC_SRC := $(JDK_TOPDIR)/src/java.base/unix/native/launcher
endif
ifeq ($(OPENJDK_TARGET_OS), linux)
BUILD_JEXEC_DST_DIR := $(SUPPORT_OUTPUTDIR)/modules_libs/java.base
BUILD_JEXEC_INC += -I$(JDK_TOPDIR)/src/java.base/share/native/libjli
endif
endif
#
# Note that the two Makefile's seems to contradict each other,
# and that src/macosx/bin/jexec.c seems unused
#
ifneq ($(BUILD_JEXEC_SRC), )
$(eval $(call SetupNativeCompilation,BUILD_JEXEC, \
SRC := $(BUILD_JEXEC_SRC), \
$(eval $(call SetupNativeCompilation, BUILD_JEXEC, \
SRC := $(JDK_TOPDIR)/src/$(MODULE)/unix/native/launcher, \
INCLUDE_FILES := jexec.c, \
OPTIMIZATION := LOW, \
CFLAGS := $(CFLAGS_JDKEXE) \
$(BUILD_JEXEC_INC), \
-I$(JDK_TOPDIR)/src/$(MODULE)/share/native/libjli, \
CFLAGS_linux := -fPIC, \
CFLAGS_solaris := -KPIC, \
LDFLAGS := $(LDFLAGS_JDKEXE), \
OBJECT_DIR := $(SUPPORT_OUTPUTDIR)/native/$(MODULE)/jexec_obj, \
OUTPUT_DIR := $(BUILD_JEXEC_DST_DIR), \
PROGRAM := jexec))
OUTPUT_DIR := $(SUPPORT_OUTPUTDIR)/modules_libs/$(MODULE), \
PROGRAM := jexec, \
))
TARGETS += $(BUILD_JEXEC)
endif
################################################################################
BUILD_JSPAWNHELPER :=
BUILD_JSPAWNHELPER_SRC := $(JDK_TOPDIR)/src/java.base/unix/native/jspawnhelper
JSPAWNHELPER_CFLAGS := -I$(JDK_TOPDIR)/src/java.base/unix/native/libjava
BUILD_JSPAWNHELPER_DST_DIR := $(SUPPORT_OUTPUTDIR)/modules_libs/java.base
LINK_JSPAWNHELPER_OBJECTS := $(SUPPORT_OUTPUTDIR)/native/$(MODULE)/libjava/childproc.o
BUILD_JSPAWNHELPER_LDFLAGS :=
ifneq ($(findstring $(OPENJDK_TARGET_OS), macosx solaris aix), )
BUILD_JSPAWNHELPER := 1
endif
ifeq ($(OPENJDK_TARGET_OS), macosx)
BUILD_JSPAWNHELPER_DST_DIR := $(SUPPORT_OUTPUTDIR)/modules_libs/java.base
endif
ifeq ($(OPENJDK_TARGET_CPU_BITS), 64)
BUILD_JSPAWNHELPER_LDFLAGS += $(COMPILER_TARGET_BITS_FLAG)64
endif
ifeq ($(BUILD_JSPAWNHELPER), 1)
$(eval $(call SetupNativeCompilation,BUILD_JSPAWNHELPER, \
SRC := $(BUILD_JSPAWNHELPER_SRC), \
INCLUDE_FILES := jspawnhelper.c, \
$(eval $(call SetupNativeCompilation, BUILD_JSPAWNHELPER, \
SRC := $(JDK_TOPDIR)/src/$(MODULE)/unix/native/jspawnhelper, \
OPTIMIZATION := LOW, \
CFLAGS := $(CFLAGS_JDKEXE) $(JSPAWNHELPER_CFLAGS), \
LDFLAGS := $(LDFLAGS_JDKEXE) $(BUILD_JSPAWNHELPER_LDFLAGS), \
LIBS := $(LINK_JSPAWNHELPER_OBJECTS), \
CFLAGS := $(CFLAGS_JDKEXE) -I$(JDK_TOPDIR)/src/$(MODULE)/unix/native/libjava, \
EXTRA_OBJECT_FILES := $(SUPPORT_OUTPUTDIR)/native/$(MODULE)/libjava/childproc.o, \
LDFLAGS := $(LDFLAGS_JDKEXE), \
OBJECT_DIR := $(SUPPORT_OUTPUTDIR)/native/$(MODULE)/jspawnhelper, \
OUTPUT_DIR := $(BUILD_JSPAWNHELPER_DST_DIR), \
PROGRAM := jspawnhelper))
$(BUILD_JSPAWNHELPER): $(LINK_JSPAWNHELPER_OBJECTS)
OUTPUT_DIR := $(SUPPORT_OUTPUTDIR)/modules_libs/$(MODULE), \
PROGRAM := jspawnhelper, \
))
TARGETS += $(BUILD_JSPAWNHELPER)
endif

View File

@ -1,10 +1,12 @@
/*
* Copyright (c) 2014, 2016, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2017, 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.
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
@ -21,27 +23,25 @@
* questions.
*/
/*
* @test
* @key nmt
* @summary Test for deprecated message if -XX:-AutoShutdownNMT is specified
* @library /test/lib
* @modules java.base/jdk.internal.misc
* java.management
package sun.nio.ch;
import java.nio.channels.spi.AsynchronousChannelProvider;
/**
* Creates this platform's default AsynchronousChannelProvider
*/
import jdk.test.lib.process.ProcessTools;
import jdk.test.lib.process.OutputAnalyzer;
public class DefaultAsynchronousChannelProvider {
public class AutoshutdownNMT {
/**
* Prevent instantiation.
*/
private DefaultAsynchronousChannelProvider() { }
public static void main(String args[]) throws Exception {
ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
"-XX:NativeMemoryTracking=detail",
"-XX:-AutoShutdownNMT",
"-version");
OutputAnalyzer output = new OutputAnalyzer(pb.start());
output.shouldContain("Ignoring option AutoShutdownNMT");
/**
* Returns the default AsynchronousChannelProvider.
*/
public static AsynchronousChannelProvider create() {
return new AixAsynchronousChannelProvider();
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2015, 2017, 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
@ -42,7 +42,6 @@ public class DefaultSelectorProvider {
* Returns the default SelectorProvider.
*/
public static SelectorProvider create() {
return new sun.nio.ch.PollSelectorProvider();
return new PollSelectorProvider();
}
}

View File

@ -1,10 +1,12 @@
/*
* Copyright (c) 2013, 2016, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2017, 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.
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
@ -21,28 +23,25 @@
* questions.
*/
/*
* @test TestParNewCMS
* @key gc
* @bug 8065972
* @summary Test that specifying -XX:+UseParNewGC on the command line logs a warning message
* @library /test/lib
* @modules java.base/jdk.internal.misc
* java.management
*/
package sun.nio.ch;
import jdk.test.lib.process.ProcessTools;
import jdk.test.lib.process.OutputAnalyzer;
import java.nio.channels.spi.AsynchronousChannelProvider;
/**
* Creates this platform's default AsynchronousChannelProvider
*/
public class TestParNewCMS {
public class DefaultAsynchronousChannelProvider {
public static void main(String args[]) throws Exception {
ProcessBuilder pb = ProcessTools.createJavaProcessBuilder("-XX:+UseParNewGC", "-XX:+UseConcMarkSweepGC", "-version");
OutputAnalyzer output = new OutputAnalyzer(pb.start());
output.shouldContain("warning: Option UseParNewGC was deprecated in version");
output.shouldNotContain("error");
output.shouldHaveExitValue(0);
}
/**
* Prevent instantiation.
*/
private DefaultAsynchronousChannelProvider() { }
/**
* Returns the default AsynchronousChannelProvider.
*/
public static AsynchronousChannelProvider create() {
return new LinuxAsynchronousChannelProvider();
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2015, 2017, 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
@ -42,7 +42,6 @@ public class DefaultSelectorProvider {
* Returns the default SelectorProvider.
*/
public static SelectorProvider create() {
return new sun.nio.ch.EPollSelectorProvider();
return new EPollSelectorProvider();
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2008, 2012, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2017, 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
@ -26,10 +26,9 @@
package sun.nio.ch;
import java.nio.channels.spi.AsynchronousChannelProvider;
import sun.security.action.GetPropertyAction;
/**
* Creates this platform's default asynchronous channel provider
* Creates this platform's default AsynchronousChannelProvider
*/
public class DefaultAsynchronousChannelProvider {
@ -39,37 +38,10 @@ public class DefaultAsynchronousChannelProvider {
*/
private DefaultAsynchronousChannelProvider() { }
@SuppressWarnings("unchecked")
private static AsynchronousChannelProvider createProvider(String cn) {
Class<AsynchronousChannelProvider> c;
try {
c = (Class<AsynchronousChannelProvider>)Class.forName(cn);
} catch (ClassNotFoundException x) {
throw new AssertionError(x);
}
try {
@SuppressWarnings("deprecation")
AsynchronousChannelProvider result = c.newInstance();
return result;
} catch (IllegalAccessException | InstantiationException x) {
throw new AssertionError(x);
}
}
/**
* Returns the default AsynchronousChannelProvider.
*/
public static AsynchronousChannelProvider create() {
String osname = GetPropertyAction.privilegedGetProperty("os.name");
if (osname.equals("SunOS"))
return createProvider("sun.nio.ch.SolarisAsynchronousChannelProvider");
if (osname.equals("Linux"))
return createProvider("sun.nio.ch.LinuxAsynchronousChannelProvider");
if (osname.contains("OS X"))
return createProvider("sun.nio.ch.BsdAsynchronousChannelProvider");
if (osname.equals("AIX"))
return createProvider("sun.nio.ch.AixAsynchronousChannelProvider");
throw new InternalError("platform not recognized");
return new BsdAsynchronousChannelProvider();
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2011, 2012, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2011, 2017, 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
@ -42,7 +42,6 @@ public class DefaultSelectorProvider {
* Returns the default SelectorProvider.
*/
public static SelectorProvider create() {
return new sun.nio.ch.KQueueSelectorProvider();
return new KQueueSelectorProvider();
}
}

View File

@ -1,239 +0,0 @@
/*
* Copyright (c) 1999, 2012, 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. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* 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.
*/
/*
* jexec for J2SE
*
* jexec is used by the system to allow execution of JAR files.
* Essentially jexec needs to run java and
* needs to be a native ISA executable (not a shell script), although
* this native ISA executable requirement was a mistake that will be fixed.
* (<ISA> is sparc or i386 or amd64).
*
* When you execute a jar file, jexec is executed by the system as follows:
* /usr/java/jre/lib/<ISA>/jexec -jar JARFILENAME
* so this just needs to be turned into:
* /usr/java/jre/bin/java -jar JARFILENAME
*
* Solaris systems (new 7's and all 8's) will be looking for jexec at:
* /usr/java/jre/lib/<ISA>/jexec
* Older systems may need to add this to their /etc/system file:
* set javaexec:jexec="/usr/java/jre/lib/<ISA>/jexec"
* and reboot the machine for this to work.
*
* This source should be compiled as:
* cc -o jexec jexec.c
*
* And jexec should be placed at the following location of the installation:
* <INSTALLATIONDIR>/jre/lib/<ISA>/jexec (for Solaris)
* <INSTALLATIONDIR>/lib/jexec (for Linux)
*
* NOTE: Unless <INSTALLATIONDIR> is the "default" JDK on the system
* (i.e. /usr/java -> <INSTALLATIONDIR>), this jexec will not be
* found. The 1.2 java is only the default on Solaris 8 and
* on systems where the 1.2 packages were installed and no 1.1
* java was found.
*
* NOTE: You must use 1.2 jar to build your jar files. The system
* doesn't seem to pick up 1.1 jar files.
*
* NOTE: We don't need to set LD_LIBRARY_PATH here, even though we
* are running the actual java binary because the java binary will
* look for it's libraries through it's own runpath, which uses
* $ORIGIN.
*
* NOTE: This jexec should NOT have any special .so library needs because
* it appears that this executable will NOT get the $ORIGIN of jexec
* but the $ORIGIN of the jar file being executed. Be careful to keep
* this program simple and with no .so dependencies.
*/
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <limits.h>
#include <errno.h>
static const int CRAZY_EXEC = ENOEXEC;
static const int BAD_MAGIC = ENOEXEC;
static const char * BAD_EXEC_MSG = "jexec failed";
static const char * CRAZY_EXEC_MSG = "missing args";
static const char * MISSING_JAVA_MSG = "can't locate java";
static const char * UNKNOWN_ERROR = "unknown error";
/* Define a constant that represents the number of directories to pop off the
* current location to find the java binary */
static const int RELATIVE_DEPTH = 3;
/* path to java after popping */
static const char * BIN_PATH = "/bin/java";
/* flag used when running JAR files */
static const char * JAR_FLAG = "-jar";
int main(int argc, const char * argv[]);
void errorExit(int error, const char * message);
int getJavaPath(const char * path, char * buf, int depth);
/*
* This is the main entry point. This program (jexec) will attempt to execute
* a JAR file by finding the Java program (java), relative to its own location.
* The exact location of the Java program depends on the platform, i.e.
*
* <INSTALLATIONDIR>/jre/lib/<ISA>/jexec (for Solaris)
* <INSTALLATIONDIR>/lib/jexec (for Linux JDK)
*
* Once the Java program is found, this program copies any remaining arguments
* into another array, which is then used to exec the Java program.
*
* On Linux this program does some additional steps. When copying the array of
* args, it is necessary to insert the "-jar" flag between arg[0], the program
* name, and the original arg[1], which is presumed to be a path to a JAR file.
* It is also necessary to verify that the original arg[1] really is a JAR file.
* (These steps are unnecessary on Solaris because they are taken care of by
* the kernel.)
*/
int main(int argc, const char * argv[]) {
/* We need to exec the original arguments using java, instead of jexec.
* Also, for Linux, it is necessary to add the "-jar" argument between
* the new arg[0], and the old arg[1]. To do this we will create a new
* args array. */
char java[PATH_MAX + 1]; /* path to java binary */
const char ** nargv = NULL; /* new args array */
int nargc = 0; /* new args array count */
int argi = 0; /* index into old array */
/* Make sure we have something to work with */
if ((argc < 1) || (argv == NULL)) {
/* Shouldn't happen... */
errorExit(CRAZY_EXEC, CRAZY_EXEC_MSG);
}
/* Get the path to the java binary, which is in a known position relative
* to our current position, which is in argv[0]. */
if (getJavaPath(argv[argi++], java, RELATIVE_DEPTH) != 0) {
errorExit(errno, MISSING_JAVA_MSG);
}
nargv = (const char **) malloc((argc + 2) * (sizeof (const char *)));
nargv[nargc++] = java;
if (argc >= 2) {
const char * jarfile = argv[argi++];
const char * message = NULL;
/* the next argument is the path to the JAR file */
nargv[nargc++] = jarfile;
}
/* finally copy any remaining arguments */
while (argi < argc) {
nargv[nargc++] = argv[argi++];
}
/* finally add one last terminating null */
nargv[nargc++] = NULL;
/* It's time to exec the java binary with the new arguments. It
* is possible that we've reached this point without actually
* having a JAR file argument (i.e. if argc < 2), but we still
* want to exec the java binary, since that will take care of
* displaying the correct usage. */
execv(java, (char * const *) nargv);
/* If the exec worked, this process would have been replaced
* by the new process. So any code reached beyond this point
* implies an error in the exec. */
free(nargv);
errorExit(errno, BAD_EXEC_MSG);
return 0; // keep the compiler happy
}
/*
* Exit the application by setting errno, and writing a message.
*
* Parameters:
* error - errno is set to this value, and it is used to exit.
* message - the message to write.
*/
void errorExit(int error, const char * message) {
if (error != 0) {
errno = error;
perror((message != NULL) ? message : UNKNOWN_ERROR);
}
exit((error == 0) ? 0 : 1);
}
/*
* Get the path to the java binary that should be relative to the current path.
*
* Parameters:
* path - the input path that the java binary that should be relative to.
* buf - a buffer of size PATH_MAX or greater that the java path is
* copied to.
* depth - the number of names to trim off the current path, including the
* name of this program.
*
* Returns:
* This function returns 0 on success; otherwise it returns the value of
* errno.
*/
int getJavaPath(const char * path, char * buf, int depth) {
int result = 0;
/* Get the full path to this program. Depending on whether this is Solaris
* or Linux, this will be something like,
*
* <FOO>/jre/lib/<ISA>/jexec (for Solaris)
* <FOO>/lib/jexec (for Linux)
*/
if (realpath(path, buf) != NULL) {
int count = 0;
/* Pop off the filename, and then subdirectories for each level of
* depth */
for (count = 0; count < depth; count++) {
*(strrchr(buf, '/')) = '\0';
}
/* Append the relative location of java, creating something like,
*
* <FOO>/jre/bin/java (for Solaris)
* <FOO>/bin/java (for Linux)
*/
strcat(buf, BIN_PATH);
}
else {
/* Failed to get the path */
result = errno;
}
return (result);
}

View File

@ -534,6 +534,8 @@ public final class System {
* @param x object for which the hashCode is to be calculated
* @return the hashCode
* @since 1.1
* @see Object#hashCode
* @see java.util.Objects#hashCode(Object)
*/
@HotSpotIntrinsicCandidate
public static native int identityHashCode(Object x);

View File

@ -98,21 +98,17 @@ abstract class DelegatingMethodHandle extends MethodHandle {
Object constraint,
NamedFunction getTargetFn) {
// No pre-action needed.
return makeReinvokerForm(target, whichCache, constraint, null, true, getTargetFn, null);
return makeReinvokerForm(target, whichCache, constraint, true, getTargetFn, null);
}
/** Create a LF which simply reinvokes a target of the given basic type. */
static LambdaForm makeReinvokerForm(MethodHandle target,
int whichCache,
Object constraint,
String debugString,
boolean forceInline,
NamedFunction getTargetFn,
NamedFunction preActionFn) {
MethodType mtype = target.type().basicType();
Kind kind = whichKind(whichCache);
if (debugString == null) {
debugString = kind.defaultLambdaName;
}
boolean customized = (whichCache < 0 ||
mtype.parameterSlotCount() > MethodType.MAX_MH_INVOKER_ARITY);
boolean hasPreAction = (preActionFn != null);
@ -144,7 +140,7 @@ abstract class DelegatingMethodHandle extends MethodHandle {
targetArgs[0] = names[NEXT_MH]; // overwrite this MH with next MH
names[REINVOKE] = new LambdaForm.Name(mtype, targetArgs);
}
form = new LambdaForm(debugString, ARG_LIMIT, names, forceInline, kind);
form = new LambdaForm(ARG_LIMIT, names, forceInline, kind);
if (!customized) {
form = mtype.form().setCachedLambdaForm(whichCache, form);
}

View File

@ -242,8 +242,7 @@ class DirectMethodHandle extends MethodHandle {
result = NEW_OBJ;
}
names[LINKER_CALL] = new Name(linker, outArgs);
String lambdaName = kind.defaultLambdaName + "_" + shortenSignature(basicTypeSignature(mtype));
LambdaForm lform = new LambdaForm(lambdaName, ARG_LIMIT, names, result, kind);
LambdaForm lform = new LambdaForm(ARG_LIMIT, names, result, kind);
// This is a tricky bit of code. Don't send it through the LF interpreter.
lform.compileToBytecode();
@ -696,22 +695,33 @@ class DirectMethodHandle extends MethodHandle {
if (needsCast && isGetter)
names[POST_CAST] = new Name(NF_checkCast, names[DMH_THIS], names[LINKER_CALL]);
for (Name n : names) assert(n != null);
// add some detail to the lambdaForm debugname,
// significant only for debugging
StringBuilder nameBuilder = new StringBuilder(kind.methodName);
if (isStatic) {
nameBuilder.append("Static");
} else {
nameBuilder.append("Field");
}
if (needsCast) nameBuilder.append("Cast");
if (needsInit) nameBuilder.append("Init");
LambdaForm form;
if (needsCast || needsInit) {
// can't use the pre-generated form when casting and/or initializing
return new LambdaForm(nameBuilder.toString(), ARG_LIMIT, names, RESULT);
form = new LambdaForm(ARG_LIMIT, names, RESULT);
} else {
return new LambdaForm(nameBuilder.toString(), ARG_LIMIT, names, RESULT, kind);
form = new LambdaForm(ARG_LIMIT, names, RESULT, kind);
}
if (LambdaForm.debugNames()) {
// add some detail to the lambdaForm debugname,
// significant only for debugging
StringBuilder nameBuilder = new StringBuilder(kind.methodName);
if (isStatic) {
nameBuilder.append("Static");
} else {
nameBuilder.append("Field");
}
if (needsCast) {
nameBuilder.append("Cast");
}
if (needsInit) {
nameBuilder.append("Init");
}
LambdaForm.associateWithDebugName(form, nameBuilder.toString());
}
return form;
}
/**

View File

@ -130,7 +130,7 @@ class InvokerBytecodeGenerator {
/** For generating customized code for a single LambdaForm. */
private InvokerBytecodeGenerator(String className, LambdaForm form, MethodType invokerType) {
this(className, form.debugName, form, invokerType);
this(className, form.lambdaName(), form, invokerType);
}
/** For generating customized code for a single LambdaForm. */

View File

@ -132,7 +132,7 @@ class Invokers {
MethodType mtype = targetType;
MethodType invokerType = mtype.insertParameterTypes(0, VarHandle.class);
LambdaForm lform = varHandleMethodInvokerHandleForm(ak.methodName(), mtype, isExact);
LambdaForm lform = varHandleMethodInvokerHandleForm(ak, mtype, isExact);
VarHandle.AccessDescriptor ad = new VarHandle.AccessDescriptor(mtype, ak.at.ordinal(), ak.ordinal());
MethodHandle invoker = BoundMethodHandle.bindSingle(invokerType, lform, ad);
@ -325,9 +325,9 @@ class Invokers {
}
names[LINKER_CALL] = new Name(outCallType, outArgs);
if (customized) {
lform = new LambdaForm(kind.defaultLambdaName, INARG_LIMIT, names);
lform = new LambdaForm(INARG_LIMIT, names);
} else {
lform = new LambdaForm(kind.defaultLambdaName, INARG_LIMIT, names, kind);
lform = new LambdaForm(INARG_LIMIT, names, kind);
}
if (isLinker)
lform.compileToBytecode(); // JVM needs a real methodOop
@ -337,11 +337,10 @@ class Invokers {
}
static MemberName varHandleInvokeLinkerMethod(String name,
MethodType mtype) {
static MemberName varHandleInvokeLinkerMethod(VarHandle.AccessMode ak, MethodType mtype) {
LambdaForm lform;
if (mtype.parameterSlotCount() <= MethodType.MAX_MH_ARITY - MH_LINKER_ARG_APPENDED) {
lform = varHandleMethodGenericLinkerHandleForm(name, mtype);
lform = varHandleMethodGenericLinkerHandleForm(ak, mtype);
} else {
// TODO
throw newInternalError("Unsupported parameter slot count " + mtype.parameterSlotCount());
@ -349,7 +348,8 @@ class Invokers {
return lform.vmentry;
}
private static LambdaForm varHandleMethodGenericLinkerHandleForm(String name, MethodType mtype) {
private static LambdaForm varHandleMethodGenericLinkerHandleForm(VarHandle.AccessMode ak,
MethodType mtype) {
// TODO Cache form?
final int THIS_VH = 0;
@ -383,14 +383,18 @@ class Invokers {
MethodType outCallType = mtype.insertParameterTypes(0, VarHandle.class)
.basicType();
names[LINKER_CALL] = new Name(outCallType, outArgs);
LambdaForm lform = new LambdaForm(name + ":VarHandle_invoke_MT_" + shortenSignature(basicTypeSignature(mtype)),
ARG_LIMIT + 1, names);
LambdaForm lform = new LambdaForm(ARG_LIMIT + 1, names, VARHANDLE_LINKER);
if (LambdaForm.debugNames()) {
String name = ak.methodName() + ":VarHandle_invoke_MT_" +
shortenSignature(basicTypeSignature(mtype));
LambdaForm.associateWithDebugName(lform, name);
}
lform.compileToBytecode();
return lform;
}
private static LambdaForm varHandleMethodInvokerHandleForm(String name, MethodType mtype, boolean isExact) {
private static LambdaForm varHandleMethodInvokerHandleForm(VarHandle.AccessMode ak,
MethodType mtype, boolean isExact) {
// TODO Cache form?
final int THIS_MH = 0;
@ -429,10 +433,14 @@ class Invokers {
MethodType outCallType = mtype.insertParameterTypes(0, VarHandle.class)
.basicType();
names[LINKER_CALL] = new Name(outCallType, outArgs);
String debugName = isExact ? ":VarHandle_exactInvoker" : ":VarHandle_invoker";
LambdaForm lform = new LambdaForm(name + debugName + shortenSignature(basicTypeSignature(mtype)),
ARG_LIMIT, names);
Kind kind = isExact ? VARHANDLE_EXACT_INVOKER : VARHANDLE_INVOKER;
LambdaForm lform = new LambdaForm(ARG_LIMIT, names, kind);
if (LambdaForm.debugNames()) {
String name = ak.methodName() +
(isExact ? ":VarHandle_exactInvoker_" : ":VarHandle_invoker_") +
shortenSignature(basicTypeSignature(mtype));
LambdaForm.associateWithDebugName(lform, name);
}
lform.prepare();
return lform;
}
@ -543,7 +551,8 @@ class Invokers {
System.arraycopy(outArgs, 0, outArgs, PREPEND_COUNT, outArgs.length - PREPEND_COUNT);
outArgs[PREPEND_MH] = names[CALL_MH];
names[LINKER_CALL] = new Name(mtype, outArgs);
lform = new LambdaForm((skipCallSite ? "linkToTargetMethod" : "linkToCallSite"), INARG_LIMIT, names);
lform = new LambdaForm(INARG_LIMIT, names,
(skipCallSite ? LINK_TO_TARGET_METHOD : LINK_TO_CALL_SITE));
lform.compileToBytecode(); // JVM needs a real methodOop
lform = mtype.form().setCachedLambdaForm(which, lform);
return lform;

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2011, 2016, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2011, 2017, 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
@ -126,7 +126,6 @@ class LambdaForm {
final boolean forceInline;
final MethodHandle customized;
@Stable final Name[] names;
final String debugName;
final Kind kind;
MemberName vmentry; // low-level behavior, or null if not yet prepared
private boolean isCompiled;
@ -268,7 +267,7 @@ class LambdaForm {
}
enum Kind {
GENERIC(""),
GENERIC("invoke"),
ZERO("zero"),
IDENTITY("identity"),
BOUND_REINVOKER("BMH.reinvoke"),
@ -278,6 +277,8 @@ class LambdaForm {
EXACT_INVOKER("MH.exactInvoker"),
GENERIC_LINKER("MH.invoke_MT"),
GENERIC_INVOKER("MH.invoker"),
LINK_TO_TARGET_METHOD("linkToTargetMethod"),
LINK_TO_CALL_SITE("linkToCallSite"),
DIRECT_INVOKE_VIRTUAL("DMH.invokeVirtual"),
DIRECT_INVOKE_SPECIAL("DMH.invokeSpecial"),
DIRECT_INVOKE_STATIC("DMH.invokeStatic"),
@ -319,7 +320,18 @@ class LambdaForm {
GET_DOUBLE("getDouble"),
PUT_DOUBLE("putDouble"),
GET_DOUBLE_VOLATILE("getDoubleVolatile"),
PUT_DOUBLE_VOLATILE("putDoubleVolatile");
PUT_DOUBLE_VOLATILE("putDoubleVolatile"),
TRY_FINALLY("tryFinally"),
COLLECT("collect"),
CONVERT("convert"),
SPREAD("spread"),
LOOP("loop"),
FIELD("field"),
GUARD("guard"),
GUARD_WITH_CATCH("guardWithCatch"),
VARHANDLE_EXACT_INVOKER("VH.exactInvoker"),
VARHANDLE_INVOKER("VH.invoker"),
VARHANDLE_LINKER("VH.invoke_MT");
final String defaultLambdaName;
final String methodName;
@ -335,25 +347,20 @@ class LambdaForm {
}
}
LambdaForm(String debugName,
int arity, Name[] names, int result) {
this(debugName, arity, names, result, /*forceInline=*/true, /*customized=*/null, Kind.GENERIC);
LambdaForm(int arity, Name[] names, int result) {
this(arity, names, result, /*forceInline=*/true, /*customized=*/null, Kind.GENERIC);
}
LambdaForm(String debugName,
int arity, Name[] names, int result, Kind kind) {
this(debugName, arity, names, result, /*forceInline=*/true, /*customized=*/null, kind);
LambdaForm(int arity, Name[] names, int result, Kind kind) {
this(arity, names, result, /*forceInline=*/true, /*customized=*/null, kind);
}
LambdaForm(String debugName,
int arity, Name[] names, int result, boolean forceInline, MethodHandle customized) {
this(debugName, arity, names, result, forceInline, customized, Kind.GENERIC);
LambdaForm(int arity, Name[] names, int result, boolean forceInline, MethodHandle customized) {
this(arity, names, result, forceInline, customized, Kind.GENERIC);
}
LambdaForm(String debugName,
int arity, Name[] names, int result, boolean forceInline, MethodHandle customized, Kind kind) {
LambdaForm(int arity, Name[] names, int result, boolean forceInline, MethodHandle customized, Kind kind) {
assert(namesOK(arity, names));
this.arity = arity;
this.result = fixResult(result, names);
this.names = names.clone();
this.debugName = fixDebugName(debugName);
this.forceInline = forceInline;
this.customized = customized;
this.kind = kind;
@ -364,31 +371,23 @@ class LambdaForm {
compileToBytecode();
}
}
LambdaForm(String debugName,
int arity, Name[] names) {
this(debugName, arity, names, LAST_RESULT, /*forceInline=*/true, /*customized=*/null, Kind.GENERIC);
LambdaForm(int arity, Name[] names) {
this(arity, names, LAST_RESULT, /*forceInline=*/true, /*customized=*/null, Kind.GENERIC);
}
LambdaForm(String debugName,
int arity, Name[] names, Kind kind) {
this(debugName, arity, names, LAST_RESULT, /*forceInline=*/true, /*customized=*/null, kind);
LambdaForm(int arity, Name[] names, Kind kind) {
this(arity, names, LAST_RESULT, /*forceInline=*/true, /*customized=*/null, kind);
}
LambdaForm(String debugName,
int arity, Name[] names, boolean forceInline) {
this(debugName, arity, names, LAST_RESULT, forceInline, /*customized=*/null, Kind.GENERIC);
LambdaForm(int arity, Name[] names, boolean forceInline) {
this(arity, names, LAST_RESULT, forceInline, /*customized=*/null, Kind.GENERIC);
}
LambdaForm(String debugName,
int arity, Name[] names, boolean forceInline, Kind kind) {
this(debugName, arity, names, LAST_RESULT, forceInline, /*customized=*/null, kind);
LambdaForm(int arity, Name[] names, boolean forceInline, Kind kind) {
this(arity, names, LAST_RESULT, forceInline, /*customized=*/null, kind);
}
LambdaForm(String debugName,
Name[] formals, Name[] temps, Name result) {
this(debugName,
formals.length, buildNames(formals, temps, result), LAST_RESULT, /*forceInline=*/true, /*customized=*/null);
LambdaForm(Name[] formals, Name[] temps, Name result) {
this(formals.length, buildNames(formals, temps, result), LAST_RESULT, /*forceInline=*/true, /*customized=*/null);
}
LambdaForm(String debugName,
Name[] formals, Name[] temps, Name result, boolean forceInline) {
this(debugName,
formals.length, buildNames(formals, temps, result), LAST_RESULT, forceInline, /*customized=*/null);
LambdaForm(Name[] formals, Name[] temps, Name result, boolean forceInline) {
this(formals.length, buildNames(formals, temps, result), LAST_RESULT, forceInline, /*customized=*/null);
}
private static Name[] buildNames(Name[] formals, Name[] temps, Name result) {
@ -408,10 +407,9 @@ class LambdaForm {
this.arity = mt.parameterCount();
this.result = (mt.returnType() == void.class || mt.returnType() == Void.class) ? -1 : arity;
this.names = buildEmptyNames(arity, mt, result == -1);
this.debugName = "LF.zero";
this.forceInline = true;
this.customized = null;
this.kind = Kind.GENERIC;
this.kind = Kind.ZERO;
assert(nameRefsAreLegal());
assert(isEmpty());
String sig = null;
@ -436,36 +434,46 @@ class LambdaForm {
return result;
}
private static String fixDebugName(String debugName) {
if (DEBUG_NAME_COUNTERS != null) {
int under = debugName.indexOf('_');
int length = debugName.length();
if (under < 0) under = length;
String debugNameStem = debugName.substring(0, under);
Integer ctr;
synchronized (DEBUG_NAME_COUNTERS) {
ctr = DEBUG_NAME_COUNTERS.get(debugNameStem);
if (ctr == null) ctr = 0;
DEBUG_NAME_COUNTERS.put(debugNameStem, ctr+1);
}
StringBuilder buf = new StringBuilder(debugNameStem);
buf.append('_');
int leadingZero = buf.length();
buf.append((int) ctr);
for (int i = buf.length() - leadingZero; i < 3; i++)
buf.insert(leadingZero, '0');
if (under < length) {
++under; // skip "_"
while (under < length && Character.isDigit(debugName.charAt(under))) {
++under;
}
if (under < length && debugName.charAt(under) == '_') ++under;
if (under < length)
buf.append('_').append(debugName, under, length);
}
return buf.toString();
static boolean debugNames() {
return DEBUG_NAME_COUNTERS != null;
}
static void associateWithDebugName(LambdaForm form, String name) {
assert (debugNames());
synchronized (DEBUG_NAMES) {
DEBUG_NAMES.put(form, name);
}
return debugName;
}
String lambdaName() {
if (DEBUG_NAMES != null) {
synchronized (DEBUG_NAMES) {
String name = DEBUG_NAMES.get(this);
if (name == null) {
name = generateDebugName();
}
return name;
}
}
return kind.defaultLambdaName;
}
private String generateDebugName() {
assert (debugNames());
String debugNameStem = kind.defaultLambdaName;
Integer ctr = DEBUG_NAME_COUNTERS.getOrDefault(debugNameStem, 0);
DEBUG_NAME_COUNTERS.put(debugNameStem, ctr + 1);
StringBuilder buf = new StringBuilder(debugNameStem);
int leadingZero = buf.length();
buf.append((int) ctr);
for (int i = buf.length() - leadingZero; i < 3; i++) {
buf.insert(leadingZero, '0');
}
buf.append('_');
buf.append(basicTypeSignature());
String name = buf.toString();
associateWithDebugName(this, name);
return name;
}
private static boolean namesOK(int arity, Name[] names) {
@ -482,7 +490,7 @@ class LambdaForm {
/** Customize LambdaForm for a particular MethodHandle */
LambdaForm customize(MethodHandle mh) {
LambdaForm customForm = new LambdaForm(debugName, arity, names, result, forceInline, mh, kind);
LambdaForm customForm = new LambdaForm(arity, names, result, forceInline, mh, kind);
if (COMPILE_THRESHOLD >= 0 && isCompiled) {
// If shared LambdaForm has been compiled, compile customized version as well.
customForm.compileToBytecode();
@ -1030,7 +1038,8 @@ class LambdaForm {
}
public String toString() {
StringBuilder buf = new StringBuilder(debugName+"=Lambda(");
String lambdaName = lambdaName();
StringBuilder buf = new StringBuilder(lambdaName + "=Lambda(");
for (int i = 0; i < names.length; i++) {
if (i == arity) buf.append(")=>{");
Name n = names[i];
@ -1742,7 +1751,7 @@ class LambdaForm {
// bootstrap dependency on this method in case we're interpreting LFs
if (isVoid) {
Name[] idNames = new Name[] { argument(0, L_TYPE) };
idForm = new LambdaForm(idMem.getName(), 1, idNames, VOID_RESULT, Kind.IDENTITY);
idForm = new LambdaForm(1, idNames, VOID_RESULT, Kind.IDENTITY);
idForm.compileToBytecode();
idFun = new NamedFunction(idMem, SimpleMethodHandle.make(idMem.getInvocationType(), idForm));
@ -1750,14 +1759,14 @@ class LambdaForm {
zeFun = idFun;
} else {
Name[] idNames = new Name[] { argument(0, L_TYPE), argument(1, type) };
idForm = new LambdaForm(idMem.getName(), 2, idNames, 1, Kind.IDENTITY);
idForm = new LambdaForm(2, idNames, 1, Kind.IDENTITY);
idForm.compileToBytecode();
idFun = new NamedFunction(idMem, MethodHandleImpl.makeIntrinsic(
idMem.getInvocationType(), idForm, MethodHandleImpl.Intrinsic.IDENTITY));
Object zeValue = Wrapper.forBasicType(btChar).zero();
Name[] zeNames = new Name[] { argument(0, L_TYPE), new Name(idFun, zeValue) };
zeForm = new LambdaForm(zeMem.getName(), 1, zeNames, 1, Kind.ZERO);
zeForm = new LambdaForm(1, zeNames, 1, Kind.ZERO);
zeForm.compileToBytecode();
zeFun = new NamedFunction(zeMem, MethodHandleImpl.makeIntrinsic(
zeMem.getInvocationType(), zeForm, MethodHandleImpl.Intrinsic.ZERO));
@ -1805,11 +1814,15 @@ class LambdaForm {
}
private static final HashMap<String,Integer> DEBUG_NAME_COUNTERS;
private static final HashMap<LambdaForm,String> DEBUG_NAMES;
static {
if (debugEnabled())
if (debugEnabled()) {
DEBUG_NAME_COUNTERS = new HashMap<>();
else
DEBUG_NAMES = new HashMap<>();
} else {
DEBUG_NAME_COUNTERS = null;
DEBUG_NAMES = null;
}
}
static {

View File

@ -40,7 +40,6 @@ final class LambdaFormBuffer {
private byte flags;
private int firstChange;
private Name resultName;
private String debugName;
private ArrayList<Name> dups;
private static final int F_TRANS = 0x10, F_OWNED = 0x03;
@ -50,15 +49,15 @@ final class LambdaFormBuffer {
setNames(lf.names);
int result = lf.result;
if (result == LAST_RESULT) result = length - 1;
if (result >= 0 && lf.names[result].type != V_TYPE)
if (result >= 0 && lf.names[result].type != V_TYPE) {
resultName = lf.names[result];
debugName = lf.debugName;
}
assert(lf.nameRefsAreLegal());
}
private LambdaForm lambdaForm() {
assert(!inTrans()); // need endEdit call to tidy things up
return new LambdaForm(debugName, arity, nameArray(), resultIndex());
return new LambdaForm(arity, nameArray(), resultIndex());
}
Name name(int i) {

View File

@ -915,7 +915,7 @@ class LambdaFormEditor {
}
}
form = new LambdaForm(lambdaForm.debugName, arity2, names2, result2);
form = new LambdaForm(arity2, names2, result2);
return putInCache(key, form);
}

View File

@ -399,7 +399,7 @@ import static jdk.internal.org.objectweb.asm.Opcodes.*;
assert(RETURN_CONV == names.length-1);
}
LambdaForm form = new LambdaForm("convert", lambdaType.parameterCount(), names, RESULT);
LambdaForm form = new LambdaForm(lambdaType.parameterCount(), names, RESULT, Kind.CONVERT);
return SimpleMethodHandle.make(srcType, form);
}
@ -608,7 +608,7 @@ import static jdk.internal.org.objectweb.asm.Opcodes.*;
}
names[names.length - 1] = new Name(target, (Object[]) targetArgs);
LambdaForm form = new LambdaForm("spread", lambdaType.parameterCount(), names);
LambdaForm form = new LambdaForm(lambdaType.parameterCount(), names, Kind.SPREAD);
return SimpleMethodHandle.make(srcType, form);
}
@ -676,7 +676,7 @@ import static jdk.internal.org.objectweb.asm.Opcodes.*;
assert(inputArgPos + chunk == collectNamePos); // use of rest of input args also
names[targetNamePos] = new Name(target, (Object[]) targetArgs);
LambdaForm form = new LambdaForm("collect", lambdaType.parameterCount(), names);
LambdaForm form = new LambdaForm(lambdaType.parameterCount(), names, Kind.COLLECT);
return SimpleMethodHandle.make(srcType, form);
}
@ -774,7 +774,7 @@ import static jdk.internal.org.objectweb.asm.Opcodes.*;
@Override
public LambdaForm apply(MethodHandle target) {
return DelegatingMethodHandle.makeReinvokerForm(target,
MethodTypeForm.LF_DELEGATE_BLOCK_INLINING, CountingWrapper.class, "reinvoker.dontInline", false,
MethodTypeForm.LF_DELEGATE_BLOCK_INLINING, CountingWrapper.class, false,
DelegatingMethodHandle.NF_getTarget, CountingWrapper.NF_maybeStopCounting);
}
};
@ -943,7 +943,7 @@ import static jdk.internal.org.objectweb.asm.Opcodes.*;
invokeArgs[0] = names[SELECT_ALT];
names[CALL_TARGET] = new Name(basicType, invokeArgs);
lform = new LambdaForm("guard", lambdaType.parameterCount(), names, /*forceInline=*/true);
lform = new LambdaForm(lambdaType.parameterCount(), names, /*forceInline=*/true, Kind.GUARD);
return basicType.form().setCachedLambdaForm(MethodTypeForm.LF_GWT, lform);
}
@ -1019,7 +1019,7 @@ import static jdk.internal.org.objectweb.asm.Opcodes.*;
Object[] unboxArgs = new Object[] {names[GET_UNBOX_RESULT], names[TRY_CATCH]};
names[UNBOX_RESULT] = new Name(invokeBasicUnbox, unboxArgs);
lform = new LambdaForm("guardWithCatch", lambdaType.parameterCount(), names);
lform = new LambdaForm(lambdaType.parameterCount(), names, Kind.GUARD_WITH_CATCH);
return basicType.form().setCachedLambdaForm(MethodTypeForm.LF_GWC, lform);
}
@ -1886,7 +1886,7 @@ import static jdk.internal.org.objectweb.asm.Opcodes.*;
names[UNBOX_RESULT] = new Name(invokeBasicUnbox, unboxArgs);
lform = basicType.form().setCachedLambdaForm(MethodTypeForm.LF_LOOP,
new LambdaForm("loop", lambdaType.parameterCount(), names));
new LambdaForm(lambdaType.parameterCount(), names, Kind.LOOP));
}
// BOXED_ARGS is the index into the names array where the loop idiom starts
@ -2120,7 +2120,7 @@ import static jdk.internal.org.objectweb.asm.Opcodes.*;
Object[] unboxArgs = new Object[] {names[GET_UNBOX_RESULT], names[TRY_FINALLY]};
names[UNBOX_RESULT] = new Name(invokeBasicUnbox, unboxArgs);
lform = new LambdaForm("tryFinally", lambdaType.parameterCount(), names);
lform = new LambdaForm(lambdaType.parameterCount(), names, Kind.TRY_FINALLY);
return basicType.form().setCachedLambdaForm(MethodTypeForm.LF_TF, lform);
}

View File

@ -420,7 +420,7 @@ class MethodHandleNatives {
MethodType mtype,
Object[] appendixResult) {
// Get the signature method type
MethodType sigType = mtype.basicType();
final MethodType sigType = mtype.basicType();
// Get the access kind from the method name
VarHandle.AccessMode ak;
@ -430,32 +430,37 @@ class MethodHandleNatives {
throw MethodHandleStatics.newInternalError(e);
}
// If not polymorphic in the return type, such as the compareAndSet
// methods that return boolean
if (ak.at.isMonomorphicInReturnType) {
if (ak.at.returnType != mtype.returnType()) {
// The caller contains a different return type than that
// defined by the method
throw newNoSuchMethodErrorOnVarHandle(name, mtype);
}
// Adjust the return type of the signature method type
sigType = sigType.changeReturnType(ak.at.returnType);
}
// Get the guard method type for linking
MethodType guardType = sigType
// VarHandle at start
.insertParameterTypes(0, VarHandle.class)
// Access descriptor at end
.appendParameterTypes(VarHandle.AccessDescriptor.class);
// Create the appendix descriptor constant
VarHandle.AccessDescriptor ad = new VarHandle.AccessDescriptor(mtype, ak.at.ordinal(), ak.ordinal());
appendixResult[0] = ad;
if (MethodHandleStatics.VAR_HANDLE_GUARDS) {
// If not polymorphic in the return type, such as the compareAndSet
// methods that return boolean
Class<?> guardReturnType = sigType.returnType();
if (ak.at.isMonomorphicInReturnType) {
if (ak.at.returnType != mtype.returnType()) {
// The caller contains a different return type than that
// defined by the method
throw newNoSuchMethodErrorOnVarHandle(name, mtype);
}
// Adjust the return type of the signature method type
guardReturnType = ak.at.returnType;
}
// Get the guard method type for linking
final Class<?>[] guardParams = new Class<?>[sigType.parameterCount() + 2];
// VarHandle at start
guardParams[0] = VarHandle.class;
for (int i = 0; i < sigType.parameterCount(); i++) {
guardParams[i + 1] = sigType.parameterType(i);
}
// Access descriptor at end
guardParams[guardParams.length - 1] = VarHandle.AccessDescriptor.class;
MethodType guardType = MethodType.makeImpl(guardReturnType, guardParams, true);
MemberName linker = new MemberName(
VarHandleGuards.class, "guard_" + getVarHandleMethodSignature(sigType),
VarHandleGuards.class, getVarHandleGuardMethodName(guardType),
guardType, REF_invokeStatic);
linker = MemberName.getFactory().resolveOrNull(REF_invokeStatic, linker,
@ -466,16 +471,18 @@ class MethodHandleNatives {
// Fall back to lambda form linkage if guard method is not available
// TODO Optionally log fallback ?
}
return Invokers.varHandleInvokeLinkerMethod(name, mtype);
return Invokers.varHandleInvokeLinkerMethod(ak, mtype);
}
static String getVarHandleMethodSignature(MethodType mt) {
StringBuilder sb = new StringBuilder(mt.parameterCount() + 2);
static String getVarHandleGuardMethodName(MethodType guardType) {
String prefix = "guard_";
StringBuilder sb = new StringBuilder(prefix.length() + guardType.parameterCount());
for (int i = 0; i < mt.parameterCount(); i++) {
Class<?> pt = mt.parameterType(i);
sb.append(prefix);
for (int i = 1; i < guardType.parameterCount() - 1; i++) {
Class<?> pt = guardType.parameterType(i);
sb.append(getCharType(pt));
}
sb.append('_').append(getCharType(mt.returnType()));
sb.append('_').append(getCharType(guardType.returnType()));
return sb.toString();
}
static char getCharType(Class<?> pt) {

View File

@ -1,10 +1,12 @@
/*
* Copyright (c) 2013, 2016, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2017, 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.
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
@ -21,27 +23,25 @@
* questions.
*/
/*
* @test TestDefNewCMS
* @key gc
* @bug 8065972
* @summary Test that the unsupported DefNew+CMS combination does not start
* @library /test/lib
* @modules java.base/jdk.internal.misc
* java.management
*/
package sun.nio.ch;
import jdk.test.lib.process.ProcessTools;
import jdk.test.lib.process.OutputAnalyzer;
import java.nio.channels.spi.AsynchronousChannelProvider;
public class TestDefNewCMS {
/**
* Creates this platform's default AsynchronousChannelProvider
*/
public static void main(String args[]) throws Exception {
ProcessBuilder pb = ProcessTools.createJavaProcessBuilder("-XX:-UseParNewGC", "-XX:+UseConcMarkSweepGC", "-version");
OutputAnalyzer output = new OutputAnalyzer(pb.start());
output.shouldContain("It is not possible to combine the DefNew young collector with the CMS collector.");
output.shouldContain("Error");
output.shouldHaveExitValue(1);
}
public class DefaultAsynchronousChannelProvider {
/**
* Prevent instantiation.
*/
private DefaultAsynchronousChannelProvider() { }
/**
* Returns the default AsynchronousChannelProvider.
*/
public static AsynchronousChannelProvider create() {
return new SolarisAsynchronousChannelProvider();
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2015, 2017, 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
@ -42,7 +42,6 @@ public class DefaultSelectorProvider {
* Returns the default SelectorProvider.
*/
public static SelectorProvider create() {
return new sun.nio.ch.DevPollSelectorProvider();
return new DevPollSelectorProvider();
}
}

View File

@ -46,7 +46,13 @@ extern jobjectArray lookupIfLocalhost(JNIEnv *env, const char *hostname, jboolea
#define NI_MAXHOST 1025
#endif
/************************************************************************
#define SET_NONBLOCKING(fd) { \
int flags = fcntl(fd, F_GETFL); \
flags |= O_NONBLOCK; \
fcntl(fd, F_SETFL, flags); \
}
/*
* Inet4AddressImpl
*/
@ -57,35 +63,26 @@ extern jobjectArray lookupIfLocalhost(JNIEnv *env, const char *hostname, jboolea
*/
JNIEXPORT jstring JNICALL
Java_java_net_Inet4AddressImpl_getLocalHostName(JNIEnv *env, jobject this) {
char hostname[NI_MAXHOST+1];
char hostname[NI_MAXHOST + 1];
hostname[0] = '\0';
if (gethostname(hostname, NI_MAXHOST)) {
/* Something went wrong, maybe networking is not setup? */
if (gethostname(hostname, NI_MAXHOST) != 0) {
strcpy(hostname, "localhost");
} else {
// try to resolve hostname via nameservice
// if it is known but getnameinfo fails, hostname will still be the
// value from gethostname
struct addrinfo hints, *res;
int error;
// make sure string is null-terminated
hostname[NI_MAXHOST] = '\0';
memset(&hints, 0, sizeof(hints));
hints.ai_flags = AI_CANONNAME;
hints.ai_family = AF_INET;
error = getaddrinfo(hostname, NULL, &hints, &res);
if (error == 0) {/* host is known to name service */
getnameinfo(res->ai_addr,
res->ai_addrlen,
hostname,
NI_MAXHOST,
NULL,
0,
NI_NAMEREQD);
/* if getnameinfo fails hostname is still the value
from gethostname */
if (getaddrinfo(hostname, NULL, &hints, &res) == 0) {
getnameinfo(res->ai_addr, res->ai_addrlen, hostname, NI_MAXHOST,
NULL, 0, NI_NAMEREQD);
freeaddrinfo(res);
}
}
@ -93,89 +90,70 @@ Java_java_net_Inet4AddressImpl_getLocalHostName(JNIEnv *env, jobject this) {
}
/*
* Find an internet address for a given hostname. Note that this
* Find an internet address for a given hostname. Note that this
* code only works for addresses of type INET. The translation
* of %d.%d.%d.%d to an address (int) occurs in java now, so the
* String "host" shouldn't *ever* be a %d.%d.%d.%d string
* String "host" shouldn't be a %d.%d.%d.%d string. The only
* exception should be when any of the %d are out of range and
* we fallback to a lookup.
*
* Class: java_net_Inet4AddressImpl
* Method: lookupAllHostAddr
* Signature: (Ljava/lang/String;)[[B
*/
JNIEXPORT jobjectArray JNICALL
Java_java_net_Inet4AddressImpl_lookupAllHostAddr(JNIEnv *env, jobject this,
jstring host) {
jstring host) {
jobjectArray ret = NULL;
const char *hostname;
jobjectArray ret = 0;
int retLen = 0;
int error = 0;
struct addrinfo hints, *res, *resNew = NULL;
struct addrinfo hints, *res = NULL, *resNew = NULL, *last = NULL,
*iterator;
initInetAddressIDs(env);
JNU_CHECK_EXCEPTION_RETURN(env, NULL);
if (IS_NULL(host)) {
JNU_ThrowNullPointerException(env, "host is null");
return 0;
JNU_ThrowNullPointerException(env, "host argument is null");
return NULL;
}
hostname = JNU_GetStringPlatformChars(env, host, JNI_FALSE);
CHECK_NULL_RETURN(hostname, NULL);
/* Try once, with our static buffer. */
// try once, with our static buffer
memset(&hints, 0, sizeof(hints));
hints.ai_flags = AI_CANONNAME;
hints.ai_family = AF_INET;
#ifdef __solaris__
/*
* Workaround for Solaris bug 4160367 - if a hostname contains a
* white space then 0.0.0.0 is returned
*/
if (isspace((unsigned char)hostname[0])) {
JNU_ThrowByName(env, JNU_JAVANETPKG "UnknownHostException",
(char *)hostname);
JNU_ReleaseStringPlatformChars(env, host, hostname);
return NULL;
}
#endif
error = getaddrinfo(hostname, NULL, &hints, &res);
#ifdef MACOSX
if (error) {
#if defined(MACOSX)
// If getaddrinfo fails try getifaddrs, see bug 8170910.
ret = lookupIfLocalhost(env, hostname, JNI_FALSE);
if (ret != NULL || (*env)->ExceptionCheck(env)) {
JNU_ReleaseStringPlatformChars(env, host, hostname);
return ret;
goto cleanupAndReturn;
}
}
#endif
if (error) {
/* report error */
// report error
NET_ThrowUnknownHostExceptionWithGaiError(env, hostname, error);
JNU_ReleaseStringPlatformChars(env, host, hostname);
return NULL;
goto cleanupAndReturn;
} else {
int i = 0;
struct addrinfo *itr, *last = NULL, *iterator = res;
iterator = res;
while (iterator != NULL) {
// remove the duplicate one
// skip duplicates
int skip = 0;
itr = resNew;
while (itr != NULL) {
struct addrinfo *iteratorNew = resNew;
while (iteratorNew != NULL) {
struct sockaddr_in *addr1, *addr2;
addr1 = (struct sockaddr_in *)iterator->ai_addr;
addr2 = (struct sockaddr_in *)itr->ai_addr;
if (addr1->sin_addr.s_addr ==
addr2->sin_addr.s_addr) {
addr2 = (struct sockaddr_in *)iteratorNew->ai_addr;
if (addr1->sin_addr.s_addr == addr2->sin_addr.s_addr) {
skip = 1;
break;
}
itr = itr->ai_next;
iteratorNew = iteratorNew->ai_next;
}
if (!skip) {
@ -199,44 +177,37 @@ Java_java_net_Inet4AddressImpl_lookupAllHostAddr(JNIEnv *env, jobject this,
iterator = iterator->ai_next;
}
retLen = i;
iterator = resNew;
ret = (*env)->NewObjectArray(env, retLen, ia_class, NULL);
// allocate array - at this point i contains the number of addresses
ret = (*env)->NewObjectArray(env, i, ia_class, NULL);
if (IS_NULL(ret)) {
/* we may have memory to free at the end of this */
goto cleanupAndReturn;
}
i = 0;
iterator = resNew;
while (iterator != NULL) {
jobject iaObj = (*env)->NewObject(env, ia4_class, ia4_ctrID);
if (IS_NULL(iaObj)) {
ret = NULL;
goto cleanupAndReturn;
}
setInetAddress_addr(env, iaObj, ntohl(((struct sockaddr_in*)iterator->ai_addr)->sin_addr.s_addr));
setInetAddress_addr(env, iaObj, ntohl(((struct sockaddr_in *)
(iterator->ai_addr))->sin_addr.s_addr));
setInetAddress_hostName(env, iaObj, host);
(*env)->SetObjectArrayElement(env, ret, i++, iaObj);
iterator = iterator->ai_next;
}
}
cleanupAndReturn:
{
struct addrinfo *iterator, *tmp;
iterator = resNew;
while (iterator != NULL) {
tmp = iterator;
iterator = iterator->ai_next;
free(tmp);
}
JNU_ReleaseStringPlatformChars(env, host, hostname);
JNU_ReleaseStringPlatformChars(env, host, hostname);
while (resNew != NULL) {
last = resNew;
resNew = resNew->ai_next;
free(last);
}
if (res != NULL) {
freeaddrinfo(res);
}
freeaddrinfo(res);
return ret;
}
@ -244,164 +215,243 @@ cleanupAndReturn:
* Class: java_net_Inet4AddressImpl
* Method: getHostByAddr
* Signature: (I)Ljava/lang/String;
*
* Theoretically the UnknownHostException could be enriched with gai error
* information. But as it is silently ignored anyway, there's no need for this.
* It's only important that either a valid hostname is returned or an
* UnknownHostException is thrown.
*/
JNIEXPORT jstring JNICALL
Java_java_net_Inet4AddressImpl_getHostByAddr(JNIEnv *env, jobject this,
jbyteArray addrArray) {
jbyteArray addrArray) {
jstring ret = NULL;
char host[NI_MAXHOST+1];
int error = 0;
int len = 0;
char host[NI_MAXHOST + 1];
jbyte caddr[4];
struct sockaddr_in him4;
struct sockaddr *sa;
jint addr;
struct sockaddr_in sa;
// construct a sockaddr_in structure
memset((char *)&sa, 0, sizeof(struct sockaddr_in));
(*env)->GetByteArrayRegion(env, addrArray, 0, 4, caddr);
addr = ((caddr[0]<<24) & 0xff000000);
addr |= ((caddr[1] <<16) & 0xff0000);
addr |= ((caddr[2] <<8) & 0xff00);
addr = ((caddr[0] << 24) & 0xff000000);
addr |= ((caddr[1] << 16) & 0xff0000);
addr |= ((caddr[2] << 8) & 0xff00);
addr |= (caddr[3] & 0xff);
memset((void *) &him4, 0, sizeof(him4));
him4.sin_addr.s_addr = htonl(addr);
him4.sin_family = AF_INET;
sa = (struct sockaddr *) &him4;
len = sizeof(him4);
sa.sin_addr.s_addr = htonl(addr);
sa.sin_family = AF_INET;
error = getnameinfo(sa, len, host, NI_MAXHOST, NULL, 0, NI_NAMEREQD);
if (!error) {
if (getnameinfo((struct sockaddr *)&sa, sizeof(struct sockaddr_in),
host, NI_MAXHOST, NULL, 0, NI_NAMEREQD)) {
JNU_ThrowByName(env, "java/net/UnknownHostException", NULL);
} else {
ret = (*env)->NewStringUTF(env, host);
}
if (ret == NULL) {
JNU_ThrowByName(env, JNU_JAVANETPKG "UnknownHostException", NULL);
if (ret == NULL) {
JNU_ThrowByName(env, "java/net/UnknownHostException", NULL);
}
}
return ret;
}
#define SET_NONBLOCKING(fd) { \
int flags = fcntl(fd, F_GETFL); \
flags |= O_NONBLOCK; \
fcntl(fd, F_SETFL, flags); \
/**
* ping implementation using tcp port 7 (echo)
*/
static jboolean
tcp_ping4(JNIEnv *env, SOCKETADDRESS *sa, SOCKETADDRESS *netif, jint timeout,
jint ttl)
{
jint fd;
int connect_rv = -1;
// open a TCP socket
fd = socket(AF_INET, SOCK_STREAM, 0);
if (fd == -1) {
// note: if you run out of fds, you may not be able to load
// the exception class, and get a NoClassDefFoundError instead.
NET_ThrowNew(env, errno, "Can't create socket");
return JNI_FALSE;
}
// set TTL
if (ttl > 0) {
setsockopt(fd, IPPROTO_IP, IP_TTL, &ttl, sizeof(ttl));
}
// A network interface was specified, so let's bind to it.
if (netif != NULL) {
if (bind(fd, &netif->sa, sizeof(struct sockaddr_in)) < 0) {
NET_ThrowNew(env, errno, "Can't bind socket");
close(fd);
return JNI_FALSE;
}
}
// Make the socket non blocking so we can use select/poll.
SET_NONBLOCKING(fd);
sa->sa4.sin_port = htons(7); // echo port
connect_rv = NET_Connect(fd, &sa->sa, sizeof(struct sockaddr_in));
// connection established or refused immediately, either way it means
// we were able to reach the host!
if (connect_rv == 0 || errno == ECONNREFUSED) {
close(fd);
return JNI_TRUE;
}
switch (errno) {
case ENETUNREACH: // Network Unreachable
case EAFNOSUPPORT: // Address Family not supported
case EADDRNOTAVAIL: // address is not available on the remote machine
#if defined(__linux__) || defined(_AIX)
// On some Linux versions, when a socket is bound to the loopback
// interface, connect will fail and errno will be set to EINVAL
// or EHOSTUNREACH. When that happens, don't throw an exception,
// just return false.
case EINVAL:
case EHOSTUNREACH: // No route to host
#endif
close(fd);
return JNI_FALSE;
case EINPROGRESS: // this is expected as we'll probably have to wait
break;
default:
NET_ThrowByNameWithLastError(env, JNU_JAVANETPKG "ConnectException",
"connect failed");
close(fd);
return JNI_FALSE;
}
timeout = NET_Wait(env, fd, NET_WAIT_CONNECT, timeout);
if (timeout >= 0) {
// connection has been established, check for error condition
socklen_t optlen = (socklen_t)sizeof(connect_rv);
if (getsockopt(fd, SOL_SOCKET, SO_ERROR, (void*)&connect_rv,
&optlen) <0)
{
connect_rv = errno;
}
if (connect_rv == 0 || connect_rv == ECONNREFUSED) {
close(fd);
return JNI_TRUE;
}
}
close(fd);
return JNI_FALSE;
}
/**
* ping implementation.
* Send a ICMP_ECHO_REQUEST packet every second until either the timeout
* expires or a answer is received.
* Returns true is an ECHO_REPLY is received, otherwise, false.
* Send an ICMP_ECHO_REQUEST packet every second until either the timeout
* expires or an answer is received.
* Returns true if an ECHO_REPLY is received, false otherwise.
*/
static jboolean
ping4(JNIEnv *env, jint fd, struct sockaddr_in* him, jint timeout,
struct sockaddr_in* netif, jint ttl) {
jint size;
jint n, hlen1, icmplen;
ping4(JNIEnv *env, jint fd, SOCKETADDRESS *sa, SOCKETADDRESS *netif,
jint timeout, jint ttl)
{
jint n, size = 60 * 1024, hlen, tmout2, seq = 1;
socklen_t len;
char sendbuf[1500];
char recvbuf[1500];
unsigned char sendbuf[1500], recvbuf[1500];
struct icmp *icmp;
struct ip *ip;
struct sockaddr_in sa_recv;
jchar pid;
jint tmout2, seq = 1;
struct timeval tv;
size_t plen;
size_t plen = ICMP_ADVLENMIN + sizeof(tv);
/* icmp_id is a 16 bit data type, therefore down cast the pid */
pid = (jchar)getpid();
size = 60*1024;
setsockopt(fd, SOL_SOCKET, SO_RCVBUF, &size, sizeof(size));
/*
* sets the ttl (max number of hops)
*/
// sets the ttl (max number of hops)
if (ttl > 0) {
setsockopt(fd, IPPROTO_IP, IP_TTL, &ttl, sizeof(ttl));
setsockopt(fd, IPPROTO_IP, IP_TTL, &ttl, sizeof(ttl));
}
/*
* a specific interface was specified, so let's bind the socket
* to that interface to ensure the requests are sent only through it.
*/
// a specific interface was specified, so let's bind the socket
// to that interface to ensure the requests are sent only through it.
if (netif != NULL) {
if (bind(fd, (struct sockaddr*)netif, sizeof(struct sockaddr_in)) < 0) {
NET_ThrowNew(env, errno, "Can't bind socket");
close(fd);
return JNI_FALSE;
}
if (bind(fd, &netif->sa, sizeof(struct sockaddr_in)) < 0) {
NET_ThrowNew(env, errno, "Can't bind socket");
close(fd);
return JNI_FALSE;
}
}
/*
* Make the socket non blocking so we can use select
*/
// icmp_id is a 16 bit data type, therefore down cast the pid
pid = (jchar)getpid();
// Make the socket non blocking so we can use select
SET_NONBLOCKING(fd);
do {
/*
* create the ICMP request
*/
icmp = (struct icmp *) sendbuf;
icmp->icmp_type = ICMP_ECHO;
icmp->icmp_code = 0;
icmp->icmp_id = htons(pid);
icmp->icmp_seq = htons(seq);
seq++;
gettimeofday(&tv, NULL);
memcpy(icmp->icmp_data, &tv, sizeof(tv));
plen = ICMP_ADVLENMIN + sizeof(tv);
icmp->icmp_cksum = 0;
icmp->icmp_cksum = in_cksum((u_short *)icmp, plen);
/*
* send it
*/
n = sendto(fd, sendbuf, plen, 0, (struct sockaddr *)him,
sizeof(struct sockaddr));
if (n < 0 && errno != EINPROGRESS ) {
#ifdef __linux__
if (errno != EINVAL && errno != EHOSTUNREACH)
/*
* On some Linux versions, when a socket is bound to the loopback
* interface, sendto will fail and errno will be set to
* EINVAL or EHOSTUNREACH. When that happens, don't throw an
* exception, just return false.
*/
#endif /*__linux__ */
NET_ThrowNew(env, errno, "Can't send ICMP packet");
close(fd);
return JNI_FALSE;
}
tmout2 = timeout > 1000 ? 1000 : timeout;
do {
tmout2 = NET_Wait(env, fd, NET_WAIT_READ, tmout2);
if (tmout2 >= 0) {
len = sizeof(sa_recv);
n = recvfrom(fd, recvbuf, sizeof(recvbuf), 0, (struct sockaddr *)&sa_recv, &len);
ip = (struct ip*) recvbuf;
hlen1 = (ip->ip_hl) << 2;
icmp = (struct icmp *) (recvbuf + hlen1);
icmplen = n - hlen1;
/*
* We did receive something, but is it what we were expecting?
* I.E.: A ICMP_ECHOREPLY packet with the proper PID.
*/
if (icmplen >= 8 && icmp->icmp_type == ICMP_ECHOREPLY
&& (ntohs(icmp->icmp_id) == pid)) {
if ((him->sin_addr.s_addr == sa_recv.sin_addr.s_addr)) {
close(fd);
return JNI_TRUE;
// create the ICMP request
icmp = (struct icmp *)sendbuf;
icmp->icmp_type = ICMP_ECHO;
icmp->icmp_code = 0;
// let's tag the ECHO packet with our pid so we can identify it
icmp->icmp_id = htons(pid);
icmp->icmp_seq = htons(seq);
seq++;
gettimeofday(&tv, NULL);
memcpy(icmp->icmp_data, &tv, sizeof(tv));
icmp->icmp_cksum = 0;
// manually calculate checksum
icmp->icmp_cksum = in_cksum((u_short *)icmp, plen);
// send it
n = sendto(fd, sendbuf, plen, 0, &sa->sa, sizeof(struct sockaddr_in));
if (n < 0 && errno != EINPROGRESS) {
#if defined(__linux__)
/*
* On some Linux versions, when a socket is bound to the loopback
* interface, sendto will fail and errno will be set to
* EINVAL or EHOSTUNREACH. When that happens, don't throw an
* exception, just return false.
*/
if (errno != EINVAL && errno != EHOSTUNREACH) {
NET_ThrowNew(env, errno, "Can't send ICMP packet");
}
if (him->sin_addr.s_addr == 0) {
close(fd);
return JNI_TRUE;
}
}
#else
NET_ThrowNew(env, errno, "Can't send ICMP packet");
#endif
close(fd);
return JNI_FALSE;
}
} while (tmout2 > 0);
timeout -= 1000;
} while (timeout >0);
tmout2 = timeout > 1000 ? 1000 : timeout;
do {
tmout2 = NET_Wait(env, fd, NET_WAIT_READ, tmout2);
if (tmout2 >= 0) {
len = sizeof(sa_recv);
n = recvfrom(fd, recvbuf, sizeof(recvbuf), 0,
(struct sockaddr *)&sa_recv, &len);
// check if we received enough data
if (n < (jint)sizeof(struct ip)) {
continue;
}
ip = (struct ip *)recvbuf;
hlen = ((jint)(unsigned int)(ip->ip_hl)) << 2;
// check if we received enough data
if (n < (jint)(hlen + sizeof(struct icmp))) {
continue;
}
icmp = (struct icmp *)(recvbuf + hlen);
// We did receive something, but is it what we were expecting?
// I.E.: An ICMP_ECHO_REPLY packet with the proper PID and
// from the host that we are trying to determine is reachable.
if (icmp->icmp_type == ICMP_ECHOREPLY &&
(ntohs(icmp->icmp_id) == pid))
{
if (sa->sa4.sin_addr.s_addr == sa_recv.sin_addr.s_addr) {
close(fd);
return JNI_TRUE;
} else if (sa->sa4.sin_addr.s_addr == 0) {
close(fd);
return JNI_TRUE;
}
}
}
} while (tmout2 > 0);
timeout -= 1000;
} while (timeout > 0);
close(fd);
return JNI_FALSE;
}
@ -413,149 +463,51 @@ ping4(JNIEnv *env, jint fd, struct sockaddr_in* him, jint timeout,
*/
JNIEXPORT jboolean JNICALL
Java_java_net_Inet4AddressImpl_isReachable0(JNIEnv *env, jobject this,
jbyteArray addrArray,
jint timeout,
jbyteArray ifArray,
jint ttl) {
jint addr;
jbyteArray addrArray, jint timeout,
jbyteArray ifArray, jint ttl)
{
jbyte caddr[4];
jint fd;
struct sockaddr_in him;
struct sockaddr_in* netif = NULL;
struct sockaddr_in inf;
int len = 0;
int connect_rv = -1;
int sz;
jint addr = 0, sz, fd;
SOCKETADDRESS sa, inf, *netif = NULL;
memset((char *) caddr, 0, sizeof(caddr));
memset((char *) &him, 0, sizeof(him));
memset((char *) &inf, 0, sizeof(inf));
// check if address array size is 4 (IPv4 address)
sz = (*env)->GetArrayLength(env, addrArray);
if (sz != 4) {
return JNI_FALSE;
}
// convert IP address from byte array to integer
memset((char *)caddr, 0, sizeof(caddr));
(*env)->GetByteArrayRegion(env, addrArray, 0, 4, caddr);
addr = ((caddr[0]<<24) & 0xff000000);
addr |= ((caddr[1] <<16) & 0xff0000);
addr |= ((caddr[2] <<8) & 0xff00);
addr = ((caddr[0] << 24) & 0xff000000);
addr |= ((caddr[1] << 16) & 0xff0000);
addr |= ((caddr[2] << 8) & 0xff00);
addr |= (caddr[3] & 0xff);
addr = htonl(addr);
him.sin_addr.s_addr = addr;
him.sin_family = AF_INET;
len = sizeof(him);
/*
* If a network interface was specified, let's create the address
* for it.
*/
memset((char *)&sa, 0, sizeof(SOCKETADDRESS));
sa.sa4.sin_addr.s_addr = htonl(addr);
sa.sa4.sin_family = AF_INET;
// If a network interface was specified, let's convert its address as well.
if (!(IS_NULL(ifArray))) {
memset((char *) caddr, 0, sizeof(caddr));
(*env)->GetByteArrayRegion(env, ifArray, 0, 4, caddr);
addr = ((caddr[0]<<24) & 0xff000000);
addr |= ((caddr[1] <<16) & 0xff0000);
addr |= ((caddr[2] <<8) & 0xff00);
addr |= (caddr[3] & 0xff);
addr = htonl(addr);
inf.sin_addr.s_addr = addr;
inf.sin_family = AF_INET;
inf.sin_port = 0;
netif = &inf;
memset((char *)caddr, 0, sizeof(caddr));
(*env)->GetByteArrayRegion(env, ifArray, 0, 4, caddr);
addr = ((caddr[0] << 24) & 0xff000000);
addr |= ((caddr[1] << 16) & 0xff0000);
addr |= ((caddr[2] << 8) & 0xff00);
addr |= (caddr[3] & 0xff);
memset((char *)&inf, 0, sizeof(SOCKETADDRESS));
inf.sa4.sin_addr.s_addr = htonl(addr);
inf.sa4.sin_family = AF_INET;
netif = &inf;
}
/*
* Let's try to create a RAW socket to send ICMP packets
* This usually requires "root" privileges, so it's likely to fail.
*/
// Let's try to create a RAW socket to send ICMP packets.
// This usually requires "root" privileges, so it's likely to fail.
fd = socket(AF_INET, SOCK_RAW, IPPROTO_ICMP);
if (fd != -1) {
/*
* It didn't fail, so we can use ICMP_ECHO requests.
*/
return ping4(env, fd, &him, timeout, netif, ttl);
}
/*
* Can't create a raw socket, so let's try a TCP socket
*/
fd = socket(AF_INET, SOCK_STREAM, 0);
if (fd == -1) {
/* note: if you run out of fds, you may not be able to load
* the exception class, and get a NoClassDefFoundError
* instead.
*/
NET_ThrowNew(env, errno, "Can't create socket");
return JNI_FALSE;
}
if (ttl > 0) {
setsockopt(fd, IPPROTO_IP, IP_TTL, &ttl, sizeof(ttl));
}
/*
* A network interface was specified, so let's bind to it.
*/
if (netif != NULL) {
if (bind(fd, (struct sockaddr*)netif, sizeof(struct sockaddr_in)) < 0) {
NET_ThrowNew(env, errno, "Can't bind socket");
close(fd);
return JNI_FALSE;
}
}
/*
* Make the socket non blocking so we can use select/poll.
*/
SET_NONBLOCKING(fd);
him.sin_port = htons(7); /* Echo */
connect_rv = NET_Connect(fd, (struct sockaddr *)&him, len);
/**
* connection established or refused immediately, either way it means
* we were able to reach the host!
*/
if (connect_rv == 0 || errno == ECONNREFUSED) {
close(fd);
return JNI_TRUE;
return tcp_ping4(env, &sa, netif, timeout, ttl);
} else {
socklen_t optlen = (socklen_t)sizeof(connect_rv);
switch (errno) {
case ENETUNREACH: /* Network Unreachable */
case EAFNOSUPPORT: /* Address Family not supported */
case EADDRNOTAVAIL: /* address is not available on the remote machine */
#if defined(__linux__) || defined(_AIX)
case EINVAL:
case EHOSTUNREACH: /* No route to host */
/*
* On some Linux versions, when a socket is bound to the loopback
* interface, connect will fail and errno will be set to EINVAL
* or EHOSTUNREACH. When that happens, don't throw an exception,
* just return false.
*/
#endif /* __linux__ */
close(fd);
return JNI_FALSE;
}
if (errno != EINPROGRESS) {
NET_ThrowByNameWithLastError(env, JNU_JAVANETPKG "ConnectException",
"connect failed");
close(fd);
return JNI_FALSE;
}
timeout = NET_Wait(env, fd, NET_WAIT_CONNECT, timeout);
if (timeout >= 0) {
/* has connection been established? */
if (getsockopt(fd, SOL_SOCKET, SO_ERROR, (void*)&connect_rv,
&optlen) <0) {
connect_rv = errno;
}
if (connect_rv == 0 || connect_rv == ECONNREFUSED) {
close(fd);
return JNI_TRUE;
}
}
close(fd);
return JNI_FALSE;
// It didn't fail, so we can use ICMP_ECHO requests.
return ping4(env, fd, &sa, netif, timeout, ttl);
}
}

View File

@ -38,17 +38,22 @@
#include "net_util.h"
#include "java_net_InetAddress.h"
#include "java_net_Inet4AddressImpl.h"
#include "java_net_Inet6AddressImpl.h"
#include "java_net_InetAddress.h"
/* the initial size of our hostent buffers */
#ifndef NI_MAXHOST
#define NI_MAXHOST 1025
#endif
#define SET_NONBLOCKING(fd) { \
int flags = fcntl(fd, F_GETFL); \
flags |= O_NONBLOCK; \
fcntl(fd, F_SETFL, flags); \
}
/************************************************************************
/*
* Inet6AddressImpl
*/
@ -59,58 +64,40 @@
*/
JNIEXPORT jstring JNICALL
Java_java_net_Inet6AddressImpl_getLocalHostName(JNIEnv *env, jobject this) {
int ret;
char hostname[NI_MAXHOST+1];
char hostname[NI_MAXHOST + 1];
hostname[0] = '\0';
ret = gethostname(hostname, NI_MAXHOST);
if (ret == -1) {
/* Something went wrong, maybe networking is not setup? */
if (gethostname(hostname, NI_MAXHOST) != 0) {
strcpy(hostname, "localhost");
} else {
// ensure null-terminated
hostname[NI_MAXHOST] = '\0';
}
#if defined(__solaris__)
if (ret == 0) {
/* Solaris doesn't want to give us a fully qualified domain name.
* We do a reverse lookup to try and get one. This works
* if DNS occurs before NIS in /etc/resolv.conf, but fails
* if NIS comes first (it still gets only a partial name).
* We use thread-safe system calls.
*/
struct addrinfo hints, *res;
int error;
} else {
// try to resolve hostname via nameservice
// if it is known but getnameinfo fails, hostname will still be the
// value from gethostname
struct addrinfo hints, *res;
// make sure string is null-terminated
hostname[NI_MAXHOST] = '\0';
memset(&hints, 0, sizeof(hints));
hints.ai_flags = AI_CANONNAME;
hints.ai_family = AF_UNSPEC;
error = getaddrinfo(hostname, NULL, &hints, &res);
if (error == 0) {
/* host is known to name service */
error = getnameinfo(res->ai_addr,
res->ai_addrlen,
hostname,
NI_MAXHOST,
NULL,
0,
NI_NAMEREQD);
/* if getnameinfo fails hostname is still the value
from gethostname */
if (getaddrinfo(hostname, NULL, &hints, &res) == 0) {
getnameinfo(res->ai_addr, res->ai_addrlen, hostname, NI_MAXHOST,
NULL, 0, NI_NAMEREQD);
freeaddrinfo(res);
}
}
#else
} else {
// make sure string is null-terminated
hostname[NI_MAXHOST] = '\0';
}
#endif
return (*env)->NewStringUTF(env, hostname);
}
#ifdef MACOSX
#if defined(MACOSX)
/* also called from Inet4AddressImpl.c */
__private_extern__ jobjectArray
lookupIfLocalhost(JNIEnv *env, const char *hostname, jboolean includeV6)
@ -163,7 +150,7 @@ lookupIfLocalhost(JNIEnv *env, const char *hostname, jboolean includeV6)
struct ifaddrs *iter = ifa;
while (iter) {
int family = iter->ifa_addr->sa_family;
if (iter->ifa_name[0] != '\0' && iter->ifa_addr)
if (iter->ifa_name[0] != '\0' && iter->ifa_addr)
{
jboolean isLoopback = iter->ifa_flags & IFF_LOOPBACK;
if (family == AF_INET) {
@ -172,9 +159,7 @@ lookupIfLocalhost(JNIEnv *env, const char *hostname, jboolean includeV6)
} else if (family == AF_INET6 && includeV6) {
addrs6++;
if (isLoopback) numV6Loopbacks++;
} else {
/* We don't care e.g. AF_LINK */
}
} // else we don't care, e.g. AF_LINK
}
iter = iter->ifa_next;
}
@ -205,9 +190,9 @@ lookupIfLocalhost(JNIEnv *env, const char *hostname, jboolean includeV6)
jboolean isLoopback = iter->ifa_flags & IFF_LOOPBACK;
int family = iter->ifa_addr->sa_family;
if (iter->ifa_name[0] != '\0' && iter->ifa_addr
&& (family == AF_INET || (family == AF_INET6 && includeV6))
&& (!isLoopback || includeLoopback))
if (iter->ifa_name[0] != '\0' && iter->ifa_addr &&
(family == AF_INET || (family == AF_INET6 && includeV6)) &&
(!isLoopback || includeLoopback))
{
int port;
int index = (family == AF_INET) ? i++ : j++;
@ -234,93 +219,65 @@ lookupIfLocalhost(JNIEnv *env, const char *hostname, jboolean includeV6)
#endif
/*
* Find an internet address for a given hostname. Note that this
* code only works for addresses of type INET. The translation
* of %d.%d.%d.%d to an address (int) occurs in java now, so the
* String "host" shouldn't *ever* be a %d.%d.%d.%d string
*
* Class: java_net_Inet6AddressImpl
* Method: lookupAllHostAddr
* Signature: (Ljava/lang/String;)[[B
*/
JNIEXPORT jobjectArray JNICALL
Java_java_net_Inet6AddressImpl_lookupAllHostAddr(JNIEnv *env, jobject this,
jstring host) {
jstring host) {
jobjectArray ret = NULL;
const char *hostname;
jobjectArray ret = 0;
int retLen = 0;
int getaddrinfo_error=0;
struct addrinfo hints, *res, *resNew = NULL;
int error = 0;
struct addrinfo hints, *res = NULL, *resNew = NULL, *last = NULL,
*iterator;
initInetAddressIDs(env);
JNU_CHECK_EXCEPTION_RETURN(env, NULL);
if (IS_NULL(host)) {
JNU_ThrowNullPointerException(env, "host is null");
return 0;
JNU_ThrowNullPointerException(env, "host argument is null");
return NULL;
}
hostname = JNU_GetStringPlatformChars(env, host, JNI_FALSE);
CHECK_NULL_RETURN(hostname, NULL);
/* Try once, with our static buffer. */
// try once, with our static buffer
memset(&hints, 0, sizeof(hints));
hints.ai_flags = AI_CANONNAME;
hints.ai_family = AF_UNSPEC;
#ifdef __solaris__
/*
* Workaround for Solaris bug 4160367 - if a hostname contains a
* white space then 0.0.0.0 is returned
*/
if (isspace((unsigned char)hostname[0])) {
JNU_ThrowByName(env, JNU_JAVANETPKG "UnknownHostException",
hostname);
JNU_ReleaseStringPlatformChars(env, host, hostname);
return NULL;
}
#endif
error = getaddrinfo(hostname, NULL, &hints, &res);
getaddrinfo_error = getaddrinfo(hostname, NULL, &hints, &res);
#ifdef MACOSX
if (getaddrinfo_error) {
/*
* If getaddrinfo fails looking up the local machine, attempt to get the
* address from getifaddrs. This ensures we get an IPv6 address for the
* local machine.
*/
if (error) {
#if defined(MACOSX)
// if getaddrinfo fails try getifaddrs
ret = lookupIfLocalhost(env, hostname, JNI_TRUE);
if (ret != NULL || (*env)->ExceptionCheck(env)) {
JNU_ReleaseStringPlatformChars(env, host, hostname);
return ret;
goto cleanupAndReturn;
}
}
#endif
if (getaddrinfo_error) {
/* report error */
NET_ThrowUnknownHostExceptionWithGaiError(
env, hostname, getaddrinfo_error);
JNU_ReleaseStringPlatformChars(env, host, hostname);
return NULL;
// report error
NET_ThrowUnknownHostExceptionWithGaiError(env, hostname, error);
goto cleanupAndReturn;
} else {
int i = 0, addressPreference = -1;
int inetCount = 0, inet6Count = 0, inetIndex = 0, inet6Index = 0, originalIndex = 0;
struct addrinfo *itr, *last = NULL, *iterator = res;
int i = 0, inetCount = 0, inet6Count = 0, inetIndex = 0,
inet6Index = 0, originalIndex = 0;
int addressPreference =
(*env)->GetStaticIntField(env, ia_class, ia_preferIPv6AddressID);;
iterator = res;
while (iterator != NULL) {
// skip duplicates
int skip = 0;
itr = resNew;
while (itr != NULL) {
if (iterator->ai_family == itr->ai_family &&
iterator->ai_addrlen == itr->ai_addrlen) {
if (itr->ai_family == AF_INET) { /* AF_INET */
struct addrinfo *iteratorNew = resNew;
while (iteratorNew != NULL) {
if (iterator->ai_family == iteratorNew->ai_family &&
iterator->ai_addrlen == iteratorNew->ai_addrlen) {
if (iteratorNew->ai_family == AF_INET) { /* AF_INET */
struct sockaddr_in *addr1, *addr2;
addr1 = (struct sockaddr_in *)iterator->ai_addr;
addr2 = (struct sockaddr_in *)itr->ai_addr;
if (addr1->sin_addr.s_addr ==
addr2->sin_addr.s_addr) {
addr2 = (struct sockaddr_in *)iteratorNew->ai_addr;
if (addr1->sin_addr.s_addr == addr2->sin_addr.s_addr) {
skip = 1;
break;
}
@ -328,7 +285,7 @@ Java_java_net_Inet6AddressImpl_lookupAllHostAddr(JNIEnv *env, jobject this,
int t;
struct sockaddr_in6 *addr1, *addr2;
addr1 = (struct sockaddr_in6 *)iterator->ai_addr;
addr2 = (struct sockaddr_in6 *)itr->ai_addr;
addr2 = (struct sockaddr_in6 *)iteratorNew->ai_addr;
for (t = 0; t < 16; t++) {
if (addr1->sin6_addr.s6_addr[t] !=
@ -337,7 +294,7 @@ Java_java_net_Inet6AddressImpl_lookupAllHostAddr(JNIEnv *env, jobject this,
}
}
if (t < 16) {
itr = itr->ai_next;
iteratorNew = iteratorNew->ai_next;
continue;
} else {
skip = 1;
@ -346,16 +303,16 @@ Java_java_net_Inet6AddressImpl_lookupAllHostAddr(JNIEnv *env, jobject this,
}
} else if (iterator->ai_family != AF_INET &&
iterator->ai_family != AF_INET6) {
/* we can't handle other family types */
// we can't handle other family types
skip = 1;
break;
}
itr = itr->ai_next;
iteratorNew = iteratorNew->ai_next;
}
if (!skip) {
struct addrinfo *next
= (struct addrinfo*) malloc(sizeof(struct addrinfo));
= (struct addrinfo *)malloc(sizeof(struct addrinfo));
if (!next) {
JNU_ThrowOutOfMemoryError(env, "Native heap allocation failed");
ret = NULL;
@ -371,39 +328,33 @@ Java_java_net_Inet6AddressImpl_lookupAllHostAddr(JNIEnv *env, jobject this,
last = next;
i++;
if (iterator->ai_family == AF_INET) {
inetCount ++;
inetCount++;
} else if (iterator->ai_family == AF_INET6) {
inet6Count ++;
inet6Count++;
}
}
iterator = iterator->ai_next;
}
retLen = i;
iterator = resNew;
ret = (*env)->NewObjectArray(env, retLen, ia_class, NULL);
// allocate array - at this point i contains the number of addresses
ret = (*env)->NewObjectArray(env, i, ia_class, NULL);
if (IS_NULL(ret)) {
/* we may have memory to free at the end of this */
goto cleanupAndReturn;
}
addressPreference = (*env)->GetStaticIntField(env, ia_class, ia_preferIPv6AddressID);
if (addressPreference == java_net_InetAddress_PREFER_IPV6_VALUE) {
/* AF_INET addresses will be offset by inet6Count */
inetIndex = inet6Count;
inet6Index = 0;
} else if (addressPreference == java_net_InetAddress_PREFER_IPV4_VALUE) {
/* AF_INET6 addresses will be offset by inetCount */
inetIndex = 0;
inet6Index = inetCount;
} else if (addressPreference == java_net_InetAddress_PREFER_SYSTEM_VALUE) {
inetIndex = inet6Index = originalIndex = 0;
}
iterator = resNew;
while (iterator != NULL) {
jboolean ret1;
if (iterator->ai_family == AF_INET) {
jobject iaObj = (*env)->NewObject(env, ia4_class, ia4_ctrID);
if (IS_NULL(iaObj)) {
@ -416,7 +367,7 @@ Java_java_net_Inet6AddressImpl_lookupAllHostAddr(JNIEnv *env, jobject this,
inetIndex++;
} else if (iterator->ai_family == AF_INET6) {
jint scope = 0;
jboolean ret1;
jobject iaObj = (*env)->NewObject(env, ia6_class, ia6_ctrID);
if (IS_NULL(iaObj)) {
ret = NULL;
@ -427,9 +378,8 @@ Java_java_net_Inet6AddressImpl_lookupAllHostAddr(JNIEnv *env, jobject this,
ret = NULL;
goto cleanupAndReturn;
}
scope = ((struct sockaddr_in6*)iterator->ai_addr)->sin6_scope_id;
if (scope != 0) { /* zero is default value, no need to set */
scope = ((struct sockaddr_in6 *)iterator->ai_addr)->sin6_scope_id;
if (scope != 0) { // zero is default value, no need to set
setInet6Address_scopeid(env, iaObj, scope);
}
setInetAddress_hostName(env, iaObj, host);
@ -443,21 +393,16 @@ Java_java_net_Inet6AddressImpl_lookupAllHostAddr(JNIEnv *env, jobject this,
iterator = iterator->ai_next;
}
}
cleanupAndReturn:
{
struct addrinfo *iterator, *tmp;
iterator = resNew;
while (iterator != NULL) {
tmp = iterator;
iterator = iterator->ai_next;
free(tmp);
}
JNU_ReleaseStringPlatformChars(env, host, hostname);
cleanupAndReturn:
JNU_ReleaseStringPlatformChars(env, host, hostname);
while (resNew != NULL) {
last = resNew;
resNew = resNew->ai_next;
free(last);
}
if (res != NULL) {
freeaddrinfo(res);
}
freeaddrinfo(res);
return ret;
}
@ -465,171 +410,252 @@ Java_java_net_Inet6AddressImpl_lookupAllHostAddr(JNIEnv *env, jobject this,
* Class: java_net_Inet6AddressImpl
* Method: getHostByAddr
* Signature: (I)Ljava/lang/String;
*
* Theoretically the UnknownHostException could be enriched with gai error
* information. But as it is silently ignored anyway, there's no need for this.
* It's only important that either a valid hostname is returned or an
* UnknownHostException is thrown.
*/
JNIEXPORT jstring JNICALL
Java_java_net_Inet6AddressImpl_getHostByAddr(JNIEnv *env, jobject this,
jbyteArray addrArray) {
jbyteArray addrArray) {
jstring ret = NULL;
char host[NI_MAXHOST+1];
int error = 0;
char host[NI_MAXHOST + 1];
int len = 0;
jbyte caddr[16];
SOCKETADDRESS sa;
struct sockaddr_in him4;
struct sockaddr_in6 him6;
struct sockaddr *sa;
memset((void *)&sa, 0, sizeof(SOCKETADDRESS));
/*
* For IPv4 addresses construct a sockaddr_in structure.
*/
// construct a sockaddr_in structure (AF_INET or AF_INET6)
if ((*env)->GetArrayLength(env, addrArray) == 4) {
jint addr;
(*env)->GetByteArrayRegion(env, addrArray, 0, 4, caddr);
addr = ((caddr[0]<<24) & 0xff000000);
addr |= ((caddr[1] <<16) & 0xff0000);
addr |= ((caddr[2] <<8) & 0xff00);
addr = ((caddr[0] << 24) & 0xff000000);
addr |= ((caddr[1] << 16) & 0xff0000);
addr |= ((caddr[2] << 8) & 0xff00);
addr |= (caddr[3] & 0xff);
memset((void *) &him4, 0, sizeof(him4));
him4.sin_addr.s_addr = htonl(addr);
him4.sin_family = AF_INET;
sa = (struct sockaddr *)&him4;
len = sizeof(him4);
sa.sa4.sin_addr.s_addr = htonl(addr);
sa.sa4.sin_family = AF_INET;
len = sizeof(struct sockaddr_in);
} else {
/*
* For IPv6 address construct a sockaddr_in6 structure.
*/
(*env)->GetByteArrayRegion(env, addrArray, 0, 16, caddr);
memset((void *)&him6, 0, sizeof(him6));
memcpy((void *)&(him6.sin6_addr), caddr, sizeof(struct in6_addr));
him6.sin6_family = AF_INET6;
sa = (struct sockaddr *)&him6;
len = sizeof(him6);
memcpy((void *)&sa.sa6.sin6_addr, caddr, sizeof(struct in6_addr));
sa.sa6.sin6_family = AF_INET6;
len = sizeof(struct sockaddr_in6);
}
error = getnameinfo(sa, len, host, NI_MAXHOST, NULL, 0, NI_NAMEREQD);
if (!error) {
if (getnameinfo(&sa.sa, len, host, NI_MAXHOST, NULL, 0, NI_NAMEREQD)) {
JNU_ThrowByName(env, "java/net/UnknownHostException", NULL);
} else {
ret = (*env)->NewStringUTF(env, host);
CHECK_NULL_RETURN(ret, NULL);
}
if (ret == NULL) {
JNU_ThrowByName(env, JNU_JAVANETPKG "UnknownHostException", NULL);
if (ret == NULL) {
JNU_ThrowByName(env, "java/net/UnknownHostException", NULL);
}
}
return ret;
}
#define SET_NONBLOCKING(fd) { \
int flags = fcntl(fd, F_GETFL); \
flags |= O_NONBLOCK; \
fcntl(fd, F_SETFL, flags); \
/**
* ping implementation using tcp port 7 (echo)
*/
static jboolean
tcp_ping6(JNIEnv *env, SOCKETADDRESS *sa, SOCKETADDRESS *netif, jint timeout,
jint ttl)
{
jint fd;
int connect_rv = -1;
// open a TCP socket
fd = socket(AF_INET6, SOCK_STREAM, 0);
if (fd == -1) {
// note: if you run out of fds, you may not be able to load
// the exception class, and get a NoClassDefFoundError instead.
NET_ThrowNew(env, errno, "Can't create socket");
return JNI_FALSE;
}
// set TTL
if (ttl > 0) {
setsockopt(fd, IPPROTO_IPV6, IPV6_UNICAST_HOPS, &ttl, sizeof(ttl));
}
// A network interface was specified, so let's bind to it.
if (netif != NULL) {
if (bind(fd, &netif->sa, sizeof(struct sockaddr_in6)) <0) {
NET_ThrowNew(env, errno, "Can't bind socket");
close(fd);
return JNI_FALSE;
}
}
// Make the socket non blocking so we can use select/poll.
SET_NONBLOCKING(fd);
sa->sa6.sin6_port = htons(7); // echo port
connect_rv = NET_Connect(fd, &sa->sa, sizeof(struct sockaddr_in6));
// connection established or refused immediately, either way it means
// we were able to reach the host!
if (connect_rv == 0 || errno == ECONNREFUSED) {
close(fd);
return JNI_TRUE;
}
switch (errno) {
case ENETUNREACH: // Network Unreachable
case EAFNOSUPPORT: // Address Family not supported
case EADDRNOTAVAIL: // address is not available on the remote machine
#if defined(__linux__) || defined(_AIX)
// On some Linux versions, when a socket is bound to the loopback
// interface, connect will fail and errno will be set to EINVAL
// or EHOSTUNREACH. When that happens, don't throw an exception,
// just return false.
case EINVAL:
case EHOSTUNREACH: // No route to host
#endif
close(fd);
return JNI_FALSE;
case EINPROGRESS: // this is expected as we'll probably have to wait
break;
default:
NET_ThrowByNameWithLastError(env, JNU_JAVANETPKG "ConnectException",
"connect failed");
close(fd);
return JNI_FALSE;
}
timeout = NET_Wait(env, fd, NET_WAIT_CONNECT, timeout);
if (timeout >= 0) {
// connection has been established, check for error condition
socklen_t optlen = (socklen_t)sizeof(connect_rv);
if (getsockopt(fd, SOL_SOCKET, SO_ERROR, (void*)&connect_rv,
&optlen) <0)
{
connect_rv = errno;
}
if (connect_rv == 0 || connect_rv == ECONNREFUSED) {
close(fd);
return JNI_TRUE;
}
}
close(fd);
return JNI_FALSE;
}
/**
* ping implementation.
* Send an ICMP_ECHO_REQUEST packet every second until either the timeout
* expires or an answer is received.
* Returns true if an ECHO_REPLY is received, false otherwise.
*/
static jboolean
ping6(JNIEnv *env, jint fd, struct sockaddr_in6* him, jint timeout,
struct sockaddr_in6* netif, jint ttl) {
jint size;
jint n;
ping6(JNIEnv *env, jint fd, SOCKETADDRESS *sa, SOCKETADDRESS *netif,
jint timeout, jint ttl)
{
jint n, size = 60 * 1024, tmout2, seq = 1;
socklen_t len;
char sendbuf[1500];
unsigned char recvbuf[1500];
unsigned char sendbuf[1500], recvbuf[1500];
struct icmp6_hdr *icmp6;
struct sockaddr_in6 sa_recv;
jbyte *caddr, *recv_caddr;
jchar pid;
jint tmout2, seq = 1;
struct timeval tv;
size_t plen;
size_t plen = sizeof(struct icmp6_hdr) + sizeof(tv);
#ifdef __linux__
{
int csum_offset;
#if defined(__linux__)
/**
* For some strange reason, the linux kernel won't calculate the
* checksum of ICMPv6 packets unless you set this socket option
*/
csum_offset = 2;
int csum_offset = 2;
setsockopt(fd, SOL_RAW, IPV6_CHECKSUM, &csum_offset, sizeof(int));
}
#endif
caddr = (jbyte *)&(him->sin6_addr);
/* icmp_id is a 16 bit data type, therefore down cast the pid */
pid = (jchar)getpid();
size = 60*1024;
setsockopt(fd, SOL_SOCKET, SO_RCVBUF, &size, sizeof(size));
// sets the ttl (max number of hops)
if (ttl > 0) {
setsockopt(fd, IPPROTO_IPV6, IPV6_UNICAST_HOPS, &ttl, sizeof(ttl));
setsockopt(fd, IPPROTO_IPV6, IPV6_UNICAST_HOPS, &ttl, sizeof(ttl));
}
// a specific interface was specified, so let's bind the socket
// to that interface to ensure the requests are sent only through it.
if (netif != NULL) {
if (bind(fd, (struct sockaddr*)netif, sizeof(struct sockaddr_in6)) <0) {
NET_ThrowNew(env, errno, "Can't bind socket");
close(fd);
return JNI_FALSE;
}
}
SET_NONBLOCKING(fd);
do {
icmp6 = (struct icmp6_hdr *) sendbuf;
icmp6->icmp6_type = ICMP6_ECHO_REQUEST;
icmp6->icmp6_code = 0;
/* let's tag the ECHO packet with our pid so we can identify it */
icmp6->icmp6_id = htons(pid);
icmp6->icmp6_seq = htons(seq);
seq++;
icmp6->icmp6_cksum = 0;
gettimeofday(&tv, NULL);
memcpy(sendbuf + sizeof(struct icmp6_hdr), &tv, sizeof(tv));
plen = sizeof(struct icmp6_hdr) + sizeof(tv);
n = sendto(fd, sendbuf, plen, 0, (struct sockaddr*) him, sizeof(struct sockaddr_in6));
if (n < 0 && errno != EINPROGRESS) {
#ifdef __linux__
if (errno != EINVAL && errno != EHOSTUNREACH)
/*
* On some Linux versions, when a socket is bound to the
* loopback interface, sendto will fail and errno will be
* set to EINVAL or EHOSTUNREACH.
* When that happens, don't throw an exception, just return false.
*/
#endif /*__linux__ */
NET_ThrowNew(env, errno, "Can't send ICMP packet");
close(fd);
return JNI_FALSE;
}
tmout2 = timeout > 1000 ? 1000 : timeout;
do {
tmout2 = NET_Wait(env, fd, NET_WAIT_READ, tmout2);
if (tmout2 >= 0) {
len = sizeof(sa_recv);
n = recvfrom(fd, recvbuf, sizeof(recvbuf), 0, (struct sockaddr*) &sa_recv, &len);
icmp6 = (struct icmp6_hdr *) (recvbuf);
recv_caddr = (jbyte *)&(sa_recv.sin6_addr);
/*
* We did receive something, but is it what we were expecting?
* I.E.: An ICMP6_ECHO_REPLY packet with the proper PID and
* from the host that we are trying to determine is reachable.
*/
if (n >= 8 && icmp6->icmp6_type == ICMP6_ECHO_REPLY &&
(ntohs(icmp6->icmp6_id) == pid)) {
if (NET_IsEqual(caddr, recv_caddr)) {
close(fd);
return JNI_TRUE;
}
if (NET_IsZeroAddr(caddr)) {
close(fd);
return JNI_TRUE;
}
}
if (bind(fd, &netif->sa, sizeof(struct sockaddr_in6)) <0) {
NET_ThrowNew(env, errno, "Can't bind socket");
close(fd);
return JNI_FALSE;
}
} while (tmout2 > 0);
timeout -= 1000;
}
// icmp_id is a 16 bit data type, therefore down cast the pid
pid = (jchar)getpid();
// Make the socket non blocking so we can use select
SET_NONBLOCKING(fd);
do {
// create the ICMP request
icmp6 = (struct icmp6_hdr *)sendbuf;
icmp6->icmp6_type = ICMP6_ECHO_REQUEST;
icmp6->icmp6_code = 0;
// let's tag the ECHO packet with our pid so we can identify it
icmp6->icmp6_id = htons(pid);
icmp6->icmp6_seq = htons(seq);
seq++;
gettimeofday(&tv, NULL);
memcpy(sendbuf + sizeof(struct icmp6_hdr), &tv, sizeof(tv));
icmp6->icmp6_cksum = 0;
// send it
n = sendto(fd, sendbuf, plen, 0, &sa->sa, sizeof(struct sockaddr_in6));
if (n < 0 && errno != EINPROGRESS) {
#if defined(__linux__)
/*
* On some Linux versions, when a socket is bound to the loopback
* interface, sendto will fail and errno will be set to
* EINVAL or EHOSTUNREACH. When that happens, don't throw an
* exception, just return false.
*/
if (errno != EINVAL && errno != EHOSTUNREACH) {
NET_ThrowNew(env, errno, "Can't send ICMP packet");
}
#else
NET_ThrowNew(env, errno, "Can't send ICMP packet");
#endif
close(fd);
return JNI_FALSE;
}
tmout2 = timeout > 1000 ? 1000 : timeout;
do {
tmout2 = NET_Wait(env, fd, NET_WAIT_READ, tmout2);
if (tmout2 >= 0) {
len = sizeof(sa_recv);
n = recvfrom(fd, recvbuf, sizeof(recvbuf), 0,
(struct sockaddr *)&sa_recv, &len);
// check if we received enough data
if (n < (jint)sizeof(struct icmp6_hdr)) {
continue;
}
icmp6 = (struct icmp6_hdr *)recvbuf;
// We did receive something, but is it what we were expecting?
// I.E.: An ICMP6_ECHO_REPLY packet with the proper PID and
// from the host that we are trying to determine is reachable.
if (icmp6->icmp6_type == ICMP6_ECHO_REPLY &&
(ntohs(icmp6->icmp6_id) == pid))
{
if (NET_IsEqual((jbyte *)&sa->sa6.sin6_addr,
(jbyte *)&sa_recv.sin6_addr)) {
close(fd);
return JNI_TRUE;
} else if (NET_IsZeroAddr((jbyte *)&sa->sa6.sin6_addr)) {
close(fd);
return JNI_TRUE;
}
}
}
} while (tmout2 > 0);
timeout -= 1000;
} while (timeout > 0);
close(fd);
return JNI_FALSE;
@ -642,157 +668,61 @@ ping6(JNIEnv *env, jint fd, struct sockaddr_in6* him, jint timeout,
*/
JNIEXPORT jboolean JNICALL
Java_java_net_Inet6AddressImpl_isReachable0(JNIEnv *env, jobject this,
jbyteArray addrArray,
jint scope,
jint timeout,
jbyteArray ifArray,
jint ttl, jint if_scope) {
jbyteArray addrArray, jint scope,
jint timeout, jbyteArray ifArray,
jint ttl, jint if_scope)
{
jbyte caddr[16];
jint fd, sz;
struct sockaddr_in6 him6;
struct sockaddr_in6 inf6;
struct sockaddr_in6* netif = NULL;
int len = 0;
int connect_rv = -1;
jint sz, fd;
SOCKETADDRESS sa, inf, *netif = NULL;
/*
* If IPv6 is not enable, then we can't reach an IPv6 address, can we?
*/
// If IPv6 is not enabled, then we can't reach an IPv6 address, can we?
// Actually, we probably shouldn't even get here.
if (!ipv6_available()) {
return JNI_FALSE;
return JNI_FALSE;
}
/*
* If it's an IPv4 address, ICMP won't work with IPv4 mapped address,
* therefore, let's delegate to the Inet4Address method.
*/
// If it's an IPv4 address, ICMP won't work with IPv4 mapped address,
// therefore, let's delegate to the Inet4Address method.
sz = (*env)->GetArrayLength(env, addrArray);
if (sz == 4) {
return Java_java_net_Inet4AddressImpl_isReachable0(env, this,
addrArray,
timeout,
ifArray, ttl);
return Java_java_net_Inet4AddressImpl_isReachable0(env, this,
addrArray, timeout,
ifArray, ttl);
}
memset((void *) caddr, 0, 16);
memset((void *) &him6, 0, sizeof(him6));
// load address to SOCKETADDRESS
memset((char *)caddr, 0, 16);
(*env)->GetByteArrayRegion(env, addrArray, 0, 16, caddr);
memcpy((void *)&(him6.sin6_addr), caddr, sizeof(struct in6_addr) );
him6.sin6_family = AF_INET6;
#ifdef __linux__
if (scope > 0)
him6.sin6_scope_id = scope;
else
him6.sin6_scope_id = getDefaultIPv6Interface( &(him6.sin6_addr));
len = sizeof(struct sockaddr_in6);
#else
if (scope > 0)
him6.sin6_scope_id = scope;
len = sizeof(struct sockaddr_in6);
#endif
/*
* If a network interface was specified, let's create the address
* for it.
*/
if (!(IS_NULL(ifArray))) {
memset((void *) caddr, 0, 16);
memset((void *) &inf6, 0, sizeof(inf6));
(*env)->GetByteArrayRegion(env, ifArray, 0, 16, caddr);
memcpy((void *)&(inf6.sin6_addr), caddr, sizeof(struct in6_addr) );
inf6.sin6_family = AF_INET6;
inf6.sin6_scope_id = if_scope;
netif = &inf6;
}
/*
* If we can create a RAW socket, then when can use the ICMP ECHO_REQUEST
* otherwise we'll try a tcp socket to the Echo port (7).
* Note that this is empiric, and not connecting could mean it's blocked
* or the echo service has been disabled.
*/
fd = socket(AF_INET6, SOCK_RAW, IPPROTO_ICMPV6);
if (fd != -1) { /* Good to go, let's do a ping */
return ping6(env, fd, &him6, timeout, netif, ttl);
}
/* No good, let's fall back on TCP */
fd = socket(AF_INET6, SOCK_STREAM, 0);
if (fd == -1) {
/* note: if you run out of fds, you may not be able to load
* the exception class, and get a NoClassDefFoundError
* instead.
*/
NET_ThrowNew(env, errno, "Can't create socket");
return JNI_FALSE;
}
if (ttl > 0) {
setsockopt(fd, IPPROTO_IPV6, IPV6_UNICAST_HOPS, &ttl, sizeof(ttl));
}
/*
* A network interface was specified, so let's bind to it.
*/
if (netif != NULL) {
if (bind(fd, (struct sockaddr*)netif, sizeof(struct sockaddr_in6)) <0) {
NET_ThrowNew(env, errno, "Can't bind socket");
close(fd);
return JNI_FALSE;
}
}
SET_NONBLOCKING(fd);
him6.sin6_port = htons((short) 7); /* Echo port */
connect_rv = NET_Connect(fd, (struct sockaddr *)&him6, len);
/**
* connection established or refused immediately, either way it means
* we were able to reach the host!
*/
if (connect_rv == 0 || errno == ECONNREFUSED) {
close(fd);
return JNI_TRUE;
memset((char *)&sa, 0, sizeof(SOCKETADDRESS));
memcpy((void *)&sa.sa6.sin6_addr, caddr, sizeof(struct in6_addr));
sa.sa6.sin6_family = AF_INET6;
if (scope > 0) {
sa.sa6.sin6_scope_id = scope;
#if defined(__linux__)
} else {
socklen_t optlen = (socklen_t)sizeof(connect_rv);
sa.sa6.sin6_scope_id = getDefaultIPv6Interface(&sa.sa6.sin6_addr);
#endif
}
switch (errno) {
case ENETUNREACH: /* Network Unreachable */
case EAFNOSUPPORT: /* Address Family not supported */
case EADDRNOTAVAIL: /* address is not available on the remote machine */
#if defined(__linux__) || defined(_AIX)
case EINVAL:
case EHOSTUNREACH: /* No route to host */
/*
* On some Linux versions, when a socket is bound to the
* loopback interface, connect will fail and errno will
* be set to EINVAL or EHOSTUNREACH. When that happens,
* don't throw an exception, just return false.
*/
#endif /* __linux__ */
close(fd);
return JNI_FALSE;
}
// load network interface address to SOCKETADDRESS, if specified
if (!(IS_NULL(ifArray))) {
memset((char *)caddr, 0, 16);
(*env)->GetByteArrayRegion(env, ifArray, 0, 16, caddr);
memset((char *)&inf, 0, sizeof(SOCKETADDRESS));
memcpy((void *)&inf.sa6.sin6_addr, caddr, sizeof(struct in6_addr));
inf.sa6.sin6_family = AF_INET6;
inf.sa6.sin6_scope_id = if_scope;
netif = &inf;
}
if (errno != EINPROGRESS) {
NET_ThrowByNameWithLastError(env, JNU_JAVANETPKG "ConnectException",
"connect failed");
close(fd);
return JNI_FALSE;
}
timeout = NET_Wait(env, fd, NET_WAIT_CONNECT, timeout);
if (timeout >= 0) {
/* has connection been established */
if (getsockopt(fd, SOL_SOCKET, SO_ERROR, (void*)&connect_rv,
&optlen) <0) {
connect_rv = errno;
}
if (connect_rv == 0 || connect_rv == ECONNREFUSED) {
close(fd);
return JNI_TRUE;
}
}
close(fd);
return JNI_FALSE;
// Let's try to create a RAW socket to send ICMP packets.
// This usually requires "root" privileges, so it's likely to fail.
fd = socket(AF_INET6, SOCK_RAW, IPPROTO_ICMPV6);
if (fd == -1) {
return tcp_ping6(env, &sa, netif, timeout, ttl);
} else {
// It didn't fail, so we can use ICMP_ECHO requests.
return ping6(env, fd, &sa, netif, timeout, ttl);
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2001, 2016, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2001, 2017, 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
@ -90,29 +90,16 @@ Java_sun_nio_ch_DatagramChannelImpl_disconnect0(JNIEnv *env, jobject this,
#if defined(__solaris__)
rv = connect(fd, 0, 0);
#else
int len;
SOCKETADDRESS sa;
socklen_t len = isIPv6 ? sizeof(struct sockaddr_in6) :
sizeof(struct sockaddr_in);
memset(&sa, 0, sizeof(sa));
#ifdef AF_INET6
if (isIPv6) {
#if defined(_ALLBSD_SOURCE)
sa.sa6.sin6_family = AF_INET6;
sa.sa.sa_family = isIPv6 ? AF_INET6 : AF_INET;
#else
sa.sa6.sin6_family = AF_UNSPEC;
sa.sa.sa_family = AF_UNSPEC;
#endif
len = sizeof(struct sockaddr_in6);
} else
#endif
{
#if defined(_ALLBSD_SOURCE)
sa.sa4.sin_family = AF_INET;
#else
sa.sa4.sin_family = AF_UNSPEC;
#endif
len = sizeof(struct sockaddr_in);
}
rv = connect(fd, &sa.sa, len);
@ -126,8 +113,9 @@ Java_sun_nio_ch_DatagramChannelImpl_disconnect0(JNIEnv *env, jobject this,
*/
if (rv < 0 && errno == EAFNOSUPPORT)
rv = errno = 0;
#endif
#endif
#endif // defined(_ALLBSD_SOURCE) || defined(_AIX)
#endif // defined(__solaris__)
if (rv < 0)
handleSocketError(env, errno);

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2003, 2016, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2003, 2017, 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
@ -37,14 +37,8 @@
#include "sun_nio_ch_InheritedChannel.h"
static int matchFamily(struct sockaddr *sa) {
int family = sa->sa_family;
#ifdef AF_INET6
if (ipv6_available()) {
return (family == AF_INET6);
}
#endif
return (family == AF_INET);
static int matchFamily(SOCKETADDRESS *sa) {
return (sa->sa.sa_family == (ipv6_available() ? AF_INET6 : AF_INET));
}
JNIEXPORT void JNICALL
@ -63,7 +57,7 @@ Java_sun_nio_ch_InheritedChannel_peerAddress0(JNIEnv *env, jclass cla, jint fd)
jint remote_port;
if (getpeername(fd, &sa.sa, &len) == 0) {
if (matchFamily(&sa.sa)) {
if (matchFamily(&sa)) {
remote_ia = NET_SockaddrToInetAddress(env, &sa, (int *)&remote_port);
}
}
@ -71,7 +65,6 @@ Java_sun_nio_ch_InheritedChannel_peerAddress0(JNIEnv *env, jclass cla, jint fd)
return remote_ia;
}
JNIEXPORT jint JNICALL
Java_sun_nio_ch_InheritedChannel_peerPort0(JNIEnv *env, jclass cla, jint fd)
{
@ -80,7 +73,7 @@ Java_sun_nio_ch_InheritedChannel_peerPort0(JNIEnv *env, jclass cla, jint fd)
jint remote_port = -1;
if (getpeername(fd, &sa.sa, &len) == 0) {
if (matchFamily(&sa.sa)) {
if (matchFamily(&sa)) {
NET_SockaddrToInetAddress(env, &sa, (int *)&remote_port);
}
}
@ -92,7 +85,7 @@ JNIEXPORT jint JNICALL
Java_sun_nio_ch_InheritedChannel_soType0(JNIEnv *env, jclass cla, jint fd)
{
int sotype;
socklen_t arglen=sizeof(sotype);
socklen_t arglen = sizeof(sotype);
if (getsockopt(fd, SOL_SOCKET, SO_TYPE, (void *)&sotype, &arglen) == 0) {
if (sotype == SOCK_STREAM)
return sun_nio_ch_InheritedChannel_SOCK_STREAM;
@ -123,7 +116,7 @@ Java_sun_nio_ch_InheritedChannel_dup2(JNIEnv *env, jclass cla, jint fd, jint fd2
JNIEXPORT jint JNICALL
Java_sun_nio_ch_InheritedChannel_open0(JNIEnv *env, jclass cla, jstring path, jint oflag)
{
const char* str;
const char *str;
int oflag_actual;
/* convert to OS specific value */

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2001, 2016, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2001, 2017, 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
@ -101,23 +101,21 @@
* Copy IPv6 group, interface index, and IPv6 source address
* into group_source_req structure.
*/
#ifdef AF_INET6
static void initGroupSourceReq(JNIEnv* env, jbyteArray group, jint index,
jbyteArray source, struct group_source_req* req)
jbyteArray source, struct group_source_req *req)
{
struct sockaddr_in6* sin6;
req->gsr_interface = (uint32_t)index;
sin6 = (struct sockaddr_in6*)&(req->gsr_group);
sin6 = (struct sockaddr_in6 *)&(req->gsr_group);
sin6->sin6_family = AF_INET6;
COPY_INET6_ADDRESS(env, group, (jbyte*)&(sin6->sin6_addr));
COPY_INET6_ADDRESS(env, group, (jbyte *)&(sin6->sin6_addr));
sin6 = (struct sockaddr_in6*)&(req->gsr_source);
sin6 = (struct sockaddr_in6 *)&(req->gsr_source);
sin6->sin6_family = AF_INET6;
COPY_INET6_ADDRESS(env, source, (jbyte*)&(sin6->sin6_addr));
COPY_INET6_ADDRESS(env, source, (jbyte *)&(sin6->sin6_addr));
}
#endif
#ifdef _AIX
@ -199,18 +197,13 @@ Java_sun_nio_ch_Net_socket0(JNIEnv *env, jclass cl, jboolean preferIPv6,
{
int fd;
int type = (stream ? SOCK_STREAM : SOCK_DGRAM);
#ifdef AF_INET6
int domain = (ipv6_available() && preferIPv6) ? AF_INET6 : AF_INET;
#else
int domain = AF_INET;
#endif
fd = socket(domain, type, 0);
if (fd < 0) {
return handleSocketError(env, errno);
}
#ifdef AF_INET6
/* Disable IPV6_V6ONLY to ensure dual-socket support */
if (domain == AF_INET6) {
int arg = 0;
@ -223,7 +216,6 @@ Java_sun_nio_ch_Net_socket0(JNIEnv *env, jclass cl, jboolean preferIPv6,
return -1;
}
}
#endif
if (reuse) {
int arg = 1;
@ -250,9 +242,7 @@ Java_sun_nio_ch_Net_socket0(JNIEnv *env, jclass cl, jboolean preferIPv6,
return -1;
}
}
#endif
#if defined(__linux__) && defined(AF_INET6)
/* By default, Linux uses the route default */
if (domain == AF_INET6 && type == SOCK_DGRAM) {
int arg = 1;
@ -569,7 +559,6 @@ JNIEXPORT jint JNICALL
Java_sun_nio_ch_Net_joinOrDrop6(JNIEnv *env, jobject this, jboolean join, jobject fdo,
jbyteArray group, jint index, jbyteArray source)
{
#ifdef AF_INET6
struct ipv6_mreq mreq6;
struct group_source_req req;
int opt, n, optlen;
@ -600,21 +589,16 @@ Java_sun_nio_ch_Net_joinOrDrop6(JNIEnv *env, jobject this, jboolean join, jobjec
handleSocketError(env, errno);
}
return 0;
#else
JNU_ThrowInternalError(env, "Should not get here");
return IOS_THROWN;
#endif /* AF_INET6 */
}
JNIEXPORT jint JNICALL
Java_sun_nio_ch_Net_blockOrUnblock6(JNIEnv *env, jobject this, jboolean block, jobject fdo,
jbyteArray group, jint index, jbyteArray source)
{
#ifdef AF_INET6
#ifdef __APPLE__
#ifdef __APPLE__
/* no IPv6 exclude-mode filtering for now */
return IOS_UNAVAILABLE;
#else
#else
struct group_source_req req;
int n;
int opt = (block) ? MCAST_BLOCK_SOURCE : MCAST_UNBLOCK_SOURCE;
@ -629,10 +613,6 @@ Java_sun_nio_ch_Net_blockOrUnblock6(JNIEnv *env, jobject this, jboolean block, j
handleSocketError(env, errno);
}
return 0;
#endif
#else
JNU_ThrowInternalError(env, "Should not get here");
return IOS_THROWN;
#endif
}

View File

@ -29,60 +29,6 @@
#include "java_net_InetAddress.h"
#include "java_net_Inet4AddressImpl.h"
/*
* Returns true if hostname is in dotted IP address format. Note that this
* function performs a syntax check only. For each octet it just checks that
* the octet is at most 3 digits.
*/
jboolean isDottedIPAddress(const char *hostname, unsigned int *addrp) {
char *c = (char *)hostname;
int octets = 0;
unsigned int cur = 0;
int digit_cnt = 0;
while (*c) {
if (*c == '.') {
if (digit_cnt == 0) {
return JNI_FALSE;
} else {
if (octets < 4) {
addrp[octets++] = cur;
cur = 0;
digit_cnt = 0;
} else {
return JNI_FALSE;
}
}
c++;
continue;
}
if ((*c < '0') || (*c > '9')) {
return JNI_FALSE;
}
digit_cnt++;
if (digit_cnt > 3) {
return JNI_FALSE;
}
/* don't check if current octet > 255 */
cur = cur*10 + (*c - '0');
/* Move onto next character and check for EOF */
c++;
if (*c == '\0') {
if (octets < 4) {
addrp[octets++] = cur;
} else {
return JNI_FALSE;
}
}
}
return (jboolean)(octets == 4);
}
/*
* Inet4AddressImpl
*/
@ -93,17 +39,17 @@ jboolean isDottedIPAddress(const char *hostname, unsigned int *addrp) {
* Signature: ()Ljava/lang/String;
*/
JNIEXPORT jstring JNICALL
Java_java_net_Inet4AddressImpl_getLocalHostName (JNIEnv *env, jobject this) {
Java_java_net_Inet4AddressImpl_getLocalHostName(JNIEnv *env, jobject this) {
char hostname[256];
if (gethostname(hostname, sizeof hostname) == -1) {
if (gethostname(hostname, sizeof(hostname)) == -1) {
strcpy(hostname, "localhost");
}
return JNU_NewStringPlatform(env, hostname);
}
/*
* Find an internet address for a given hostname. Not this this
* Find an internet address for a given hostname. Note that this
* code only works for addresses of type INET. The translation
* of %d.%d.%d.%d to an address (int) occurs in java now, so the
* String "host" shouldn't be a %d.%d.%d.%d string. The only
@ -120,7 +66,6 @@ Java_java_net_Inet4AddressImpl_lookupAllHostAddr(JNIEnv *env, jobject this,
jobjectArray ret = NULL;
const char *hostname;
int error = 0;
unsigned int addr[4];
struct addrinfo hints, *res = NULL, *resNew = NULL, *last = NULL,
*iterator;
@ -134,57 +79,6 @@ Java_java_net_Inet4AddressImpl_lookupAllHostAddr(JNIEnv *env, jobject this,
hostname = JNU_GetStringPlatformChars(env, host, JNI_FALSE);
CHECK_NULL_RETURN(hostname, NULL);
/*
* The NT/2000 resolver tolerates a space in front of localhost. This
* is not consistent with other implementations of gethostbyname.
* In addition we must do a white space check on Solaris to avoid a
* bug whereby 0.0.0.0 is returned if any host name has a white space.
*/
if (isspace(hostname[0])) {
JNU_ThrowByName(env, JNU_JAVANETPKG "UnknownHostException", hostname);
goto cleanupAndReturn;
}
/*
* If the format is x.x.x.x then don't use gethostbyname as Windows
* is unable to handle octets which are out of range.
*/
if (isDottedIPAddress(hostname, &addr[0])) {
unsigned int address;
jobject iaObj;
/*
* Are any of the octets out of range?
*/
if (addr[0] > 255 || addr[1] > 255 || addr[2] > 255 || addr[3] > 255) {
JNU_ThrowByName(env, JNU_JAVANETPKG "UnknownHostException", hostname);
goto cleanupAndReturn;
}
/*
* Return an byte array with the populated address.
*/
address = (addr[3] << 24) & 0xff000000;
address |= (addr[2] << 16) & 0xff0000;
address |= (addr[1] << 8) & 0xff00;
address |= addr[0];
ret = (*env)->NewObjectArray(env, 1, ia_class, NULL);
if (IS_NULL(ret)) {
goto cleanupAndReturn;
}
iaObj = (*env)->NewObject(env, ia4_class, ia4_ctrID);
if (IS_NULL(iaObj)) {
ret = NULL;
goto cleanupAndReturn;
}
setInetAddress_addr(env, iaObj, ntohl(address));
(*env)->SetObjectArrayElement(env, ret, 0, iaObj);
goto cleanupAndReturn;
}
// try once, with our static buffer
memset(&hints, 0, sizeof(hints));
hints.ai_flags = AI_CANONNAME;
@ -193,6 +87,7 @@ Java_java_net_Inet4AddressImpl_lookupAllHostAddr(JNIEnv *env, jobject this,
error = getaddrinfo(hostname, NULL, &hints, &res);
if (error) {
// report error
NET_ThrowByNameWithLastError(env, "java/net/UnknownHostException",
hostname);
goto cleanupAndReturn;
@ -311,145 +206,86 @@ Java_java_net_Inet4AddressImpl_getHostByAddr(JNIEnv *env, jobject this,
return ret;
}
/**
* ping implementation using tcp port 7 (echo)
*/
static jboolean
tcp_ping4(JNIEnv *env,
jbyteArray addrArray,
jint timeout,
jbyteArray ifArray,
tcp_ping4(JNIEnv *env, SOCKETADDRESS *sa, SOCKETADDRESS *netif, jint timeout,
jint ttl)
{
jint addr;
jbyte caddr[4];
jint fd;
struct sockaddr_in him;
struct sockaddr_in* netif = NULL;
struct sockaddr_in inf;
int len = 0;
WSAEVENT hEvent;
int connect_rv = -1;
int sz;
WSAEVENT hEvent;
/**
* Convert IP address from byte array to integer
*/
sz = (*env)->GetArrayLength(env, addrArray);
if (sz != 4) {
return JNI_FALSE;
}
memset((char *) &him, 0, sizeof(him));
memset((char *) caddr, 0, sizeof(caddr));
(*env)->GetByteArrayRegion(env, addrArray, 0, 4, caddr);
addr = ((caddr[0]<<24) & 0xff000000);
addr |= ((caddr[1] <<16) & 0xff0000);
addr |= ((caddr[2] <<8) & 0xff00);
addr |= (caddr[3] & 0xff);
addr = htonl(addr);
/**
* Socket address
*/
him.sin_addr.s_addr = addr;
him.sin_family = AF_INET;
len = sizeof(him);
/**
* If a network interface was specified, let's convert its address
* as well.
*/
if (!(IS_NULL(ifArray))) {
memset((char *) caddr, 0, sizeof(caddr));
(*env)->GetByteArrayRegion(env, ifArray, 0, 4, caddr);
addr = ((caddr[0]<<24) & 0xff000000);
addr |= ((caddr[1] <<16) & 0xff0000);
addr |= ((caddr[2] <<8) & 0xff00);
addr |= (caddr[3] & 0xff);
addr = htonl(addr);
inf.sin_addr.s_addr = addr;
inf.sin_family = AF_INET;
inf.sin_port = 0;
netif = &inf;
}
/*
* Can't create a raw socket, so let's try a TCP socket
*/
// open a TCP socket
fd = NET_Socket(AF_INET, SOCK_STREAM, 0);
if (fd == -1) {
/* note: if you run out of fds, you may not be able to load
* the exception class, and get a NoClassDefFoundError
* instead.
*/
if (fd == SOCKET_ERROR) {
// note: if you run out of fds, you may not be able to load
// the exception class, and get a NoClassDefFoundError instead.
NET_ThrowNew(env, WSAGetLastError(), "Can't create socket");
return JNI_FALSE;
}
// set TTL
if (ttl > 0) {
setsockopt(fd, IPPROTO_IP, IP_TTL, (const char *)&ttl, sizeof(ttl));
}
/*
* A network interface was specified, so let's bind to it.
*/
// A network interface was specified, so let's bind to it.
if (netif != NULL) {
if (bind(fd, (struct sockaddr*)netif, sizeof(struct sockaddr_in)) < 0) {
if (bind(fd, &netif->sa, sizeof(struct sockaddr_in)) < 0) {
NET_ThrowNew(env, WSAGetLastError(), "Can't bind socket");
closesocket(fd);
return JNI_FALSE;
}
}
/*
* Make the socket non blocking so we can use select/poll.
*/
// Make the socket non blocking so we can use select/poll.
hEvent = WSACreateEvent();
WSAEventSelect(fd, hEvent, FD_READ|FD_CONNECT|FD_CLOSE);
/* no need to use NET_Connect as non-blocking */
him.sin_port = htons(7); /* Echo */
connect_rv = connect(fd, (struct sockaddr *)&him, len);
sa->sa4.sin_port = htons(7); // echo port
connect_rv = connect(fd, &sa->sa, sizeof(struct sockaddr_in));
/**
* connection established or refused immediately, either way it means
* we were able to reach the host!
*/
// connection established or refused immediately, either way it means
// we were able to reach the host!
if (connect_rv == 0 || WSAGetLastError() == WSAECONNREFUSED) {
WSACloseEvent(hEvent);
closesocket(fd);
return JNI_TRUE;
} else {
int optlen;
}
switch (WSAGetLastError()) {
case WSAEHOSTUNREACH: /* Host Unreachable */
case WSAENETUNREACH: /* Network Unreachable */
case WSAENETDOWN: /* Network is down */
case WSAEPFNOSUPPORT: /* Protocol Family unsupported */
switch (WSAGetLastError()) {
case WSAEHOSTUNREACH: // Host Unreachable
case WSAENETUNREACH: // Network Unreachable
case WSAENETDOWN: // Network is down
case WSAEPFNOSUPPORT: // Protocol Family unsupported
WSACloseEvent(hEvent);
closesocket(fd);
return JNI_FALSE;
case WSAEWOULDBLOCK: // this is expected as we'll probably have to wait
break;
default:
NET_ThrowByNameWithLastError(env, JNU_JAVANETPKG "ConnectException",
"connect failed");
WSACloseEvent(hEvent);
closesocket(fd);
return JNI_FALSE;
}
timeout = NET_Wait(env, fd, NET_WAIT_CONNECT, timeout);
if (timeout >= 0) {
// connection has been established, check for error condition
int optlen = sizeof(connect_rv);
if (getsockopt(fd, SOL_SOCKET, SO_ERROR, (void *)&connect_rv,
&optlen) < 0)
{
connect_rv = WSAGetLastError();
}
if (connect_rv == 0 || connect_rv == WSAECONNREFUSED) {
WSACloseEvent(hEvent);
closesocket(fd);
return JNI_FALSE;
}
if (WSAGetLastError() != WSAEWOULDBLOCK) {
NET_ThrowByNameWithLastError(env, JNU_JAVANETPKG "ConnectException",
"connect failed");
WSACloseEvent(hEvent);
closesocket(fd);
return JNI_FALSE;
}
timeout = NET_Wait(env, fd, NET_WAIT_CONNECT, timeout);
/* has connection been established */
if (timeout >= 0) {
optlen = sizeof(connect_rv);
if (getsockopt(fd, SOL_SOCKET, SO_ERROR, (void*)&connect_rv,
&optlen) <0) {
connect_rv = WSAGetLastError();
}
if (connect_rv == 0 || connect_rv == WSAECONNREFUSED) {
WSACloseEvent(hEvent);
closesocket(fd);
return JNI_TRUE;
}
return JNI_TRUE;
}
}
WSACloseEvent(hEvent);
@ -464,21 +300,17 @@ tcp_ping4(JNIEnv *env,
* Returns true is an ECHO_REPLY is received, otherwise, false.
*/
static jboolean
ping4(JNIEnv *env,
unsigned long src_addr,
unsigned long dest_addr,
jint timeout,
HANDLE hIcmpFile)
ping4(JNIEnv *env, HANDLE hIcmpFile, SOCKETADDRESS *sa,
SOCKETADDRESS *netif, jint timeout)
{
// See https://msdn.microsoft.com/en-us/library/aa366050%28VS.85%29.aspx
DWORD dwRetVal = 0;
char SendData[32] = {0};
LPVOID ReplyBuffer = NULL;
DWORD ReplySize = 0;
jboolean ret = JNI_FALSE;
// https://msdn.microsoft.com/en-us/library/windows/desktop/aa366051%28v=vs.85%29.aspx
// See https://msdn.microsoft.com/en-us/library/aa366050%28VS.85%29.aspx
// or https://msdn.microsoft.com/en-us/library/windows/desktop/aa366051%28v=vs.85%29.aspx
ReplySize = sizeof(ICMP_ECHO_REPLY) // The buffer should be large enough
// to hold at least one ICMP_ECHO_REPLY
// structure
@ -487,16 +319,16 @@ ping4(JNIEnv *env,
// to also hold 8 more bytes of data
// (the size of an ICMP error message)
ReplyBuffer = (VOID*) malloc(ReplySize);
ReplyBuffer = (VOID *)malloc(ReplySize);
if (ReplyBuffer == NULL) {
IcmpCloseHandle(hIcmpFile);
NET_ThrowNew(env, WSAGetLastError(), "Unable to allocate memory");
return JNI_FALSE;
}
if (src_addr == 0) {
if (netif == NULL) {
dwRetVal = IcmpSendEcho(hIcmpFile, // HANDLE IcmpHandle,
dest_addr, // IPAddr DestinationAddress,
sa->sa4.sin_addr.s_addr, // IPAddr DestinationAddress,
SendData, // LPVOID RequestData,
sizeof(SendData), // WORD RequestSize,
NULL, // PIP_OPTION_INFORMATION RequestOptions,
@ -506,20 +338,20 @@ ping4(JNIEnv *env,
// seem to have an undocumented minimum
// timeout of 1000ms below which the
// api behaves inconsistently.
(timeout < 1000) ? 1000 : timeout); // DWORD Timeout
(timeout < 1000) ? 1000 : timeout); // DWORD Timeout
} else {
dwRetVal = IcmpSendEcho2Ex(hIcmpFile, // HANDLE IcmpHandle,
NULL, // HANDLE Event
NULL, // PIO_APC_ROUTINE ApcRoutine
NULL, // ApcContext
src_addr, // IPAddr SourceAddress,
dest_addr, // IPAddr DestinationAddress,
netif->sa4.sin_addr.s_addr, // IPAddr SourceAddress,
sa->sa4.sin_addr.s_addr, // IPAddr DestinationAddress,
SendData, // LPVOID RequestData,
sizeof(SendData), // WORD RequestSize,
sizeof(SendData), // WORD RequestSize,
NULL, // PIP_OPTION_INFORMATION RequestOptions,
ReplyBuffer,// LPVOID ReplyBuffer,
ReplySize, // DWORD ReplySize,
(timeout < 1000) ? 1000 : timeout); // DWORD Timeout
(timeout < 1000) ? 1000 : timeout); // DWORD Timeout
}
if (dwRetVal == 0) { // if the call failed
@ -544,8 +376,8 @@ ping4(JNIEnv *env,
break;
default:
FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
NULL, err, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
(LPTSTR)&buf, 0, NULL);
NULL, err, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
(LPTSTR)&buf, 0, NULL);
NET_ThrowNew(env, err, buf);
LocalFree(buf);
break;
@ -558,8 +390,8 @@ ping4(JNIEnv *env,
// We perform an extra check to make sure that our
// roundtrip time was less than our desired timeout
// for cases where that timeout is < 1000ms.
if (pEchoReply->Status == IP_SUCCESS
&& (int)pEchoReply->RoundTripTime <= timeout)
if (pEchoReply->Status == IP_SUCCESS &&
(int)pEchoReply->RoundTripTime <= timeout)
{
ret = JNI_TRUE;
}
@ -578,57 +410,58 @@ ping4(JNIEnv *env,
*/
JNIEXPORT jboolean JNICALL
Java_java_net_Inet4AddressImpl_isReachable0(JNIEnv *env, jobject this,
jbyteArray addrArray,
jint timeout,
jbyteArray ifArray,
jint ttl) {
jint src_addr = 0;
jint dest_addr = 0;
jbyteArray addrArray, jint timeout,
jbyteArray ifArray, jint ttl)
{
jbyte caddr[4];
int sz;
jint addr = 0, sz;
SOCKETADDRESS sa, inf, *netif = NULL;
HANDLE hIcmpFile;
/**
* Convert IP address from byte array to integer
*/
// check if address array size is 4 (IPv4 address)
sz = (*env)->GetArrayLength(env, addrArray);
if (sz != 4) {
return JNI_FALSE;
}
memset((char *) caddr, 0, sizeof(caddr));
(*env)->GetByteArrayRegion(env, addrArray, 0, 4, caddr);
dest_addr = ((caddr[0]<<24) & 0xff000000);
dest_addr |= ((caddr[1] <<16) & 0xff0000);
dest_addr |= ((caddr[2] <<8) & 0xff00);
dest_addr |= (caddr[3] & 0xff);
dest_addr = htonl(dest_addr);
/**
* If a network interface was specified, let's convert its address
* as well.
*/
// convert IP address from byte array to integer
memset((char *)caddr, 0, sizeof(caddr));
(*env)->GetByteArrayRegion(env, addrArray, 0, 4, caddr);
addr = ((caddr[0] << 24) & 0xff000000);
addr |= ((caddr[1] << 16) & 0xff0000);
addr |= ((caddr[2] << 8) & 0xff00);
addr |= (caddr[3] & 0xff);
memset((char *)&sa, 0, sizeof(SOCKETADDRESS));
sa.sa4.sin_addr.s_addr = htonl(addr);
sa.sa4.sin_family = AF_INET;
// If a network interface was specified, let's convert its address as well.
if (!(IS_NULL(ifArray))) {
memset((char *) caddr, 0, sizeof(caddr));
memset((char *)caddr, 0, sizeof(caddr));
(*env)->GetByteArrayRegion(env, ifArray, 0, 4, caddr);
src_addr = ((caddr[0]<<24) & 0xff000000);
src_addr |= ((caddr[1] <<16) & 0xff0000);
src_addr |= ((caddr[2] <<8) & 0xff00);
src_addr |= (caddr[3] & 0xff);
src_addr = htonl(src_addr);
addr = ((caddr[0] << 24) & 0xff000000);
addr |= ((caddr[1] << 16) & 0xff0000);
addr |= ((caddr[2] << 8) & 0xff00);
addr |= (caddr[3] & 0xff);
memset((char *)&inf, 0, sizeof(SOCKETADDRESS));
inf.sa4.sin_addr.s_addr = htonl(addr);
inf.sa4.sin_family = AF_INET;
netif = &inf;
}
// Let's try to create an ICMP handle.
hIcmpFile = IcmpCreateFile();
if (hIcmpFile == INVALID_HANDLE_VALUE) {
int err = WSAGetLastError();
if (err == ERROR_ACCESS_DENIED) {
// fall back to TCP echo if access is denied to ICMP
return tcp_ping4(env, addrArray, timeout, ifArray, ttl);
return tcp_ping4(env, &sa, netif, timeout, ttl);
} else {
NET_ThrowNew(env, err, "Unable to create ICMP file handle");
return JNI_FALSE;
}
} else {
return ping4(env, src_addr, dest_addr, timeout, hIcmpFile);
// It didn't fail, so we can use ICMP.
return ping4(env, hIcmpFile, &sa, netif, timeout);
}
}

View File

@ -40,41 +40,40 @@
* Signature: ()Ljava/lang/String;
*/
JNIEXPORT jstring JNICALL
Java_java_net_Inet6AddressImpl_getLocalHostName (JNIEnv *env, jobject this) {
char hostname [256];
Java_java_net_Inet6AddressImpl_getLocalHostName(JNIEnv *env, jobject this) {
char hostname[256];
if (gethostname (hostname, sizeof (hostname)) == -1) {
strcpy (hostname, "localhost");
if (gethostname(hostname, sizeof(hostname)) == -1) {
strcpy(hostname, "localhost");
}
return JNU_NewStringPlatform (env, hostname);
return JNU_NewStringPlatform(env, hostname);
}
/*
* Class: java_net_Inet6AddressImpl
* Method: lookupAllHostAddr
* Signature: (Ljava/lang/String;)[[B
*/
JNIEXPORT jobjectArray JNICALL
Java_java_net_Inet6AddressImpl_lookupAllHostAddr(JNIEnv *env, jobject this,
jstring host) {
jstring host) {
jobjectArray ret = NULL;
const char *hostname;
jobjectArray ret = 0;
int retLen = 0;
jboolean preferIPv6Address;
int error=0;
struct addrinfo hints, *res = NULL, *resNew = NULL;
int error = 0;
struct addrinfo hints, *res = NULL, *resNew = NULL, *last = NULL,
*iterator;
initInetAddressIDs(env);
JNU_CHECK_EXCEPTION_RETURN(env, NULL);
if (IS_NULL(host)) {
JNU_ThrowNullPointerException(env, "host is null");
return 0;
JNU_ThrowNullPointerException(env, "host argument is null");
return NULL;
}
hostname = JNU_GetStringPlatformChars(env, host, JNI_FALSE);
CHECK_NULL_RETURN(hostname, NULL);
/* get the address preference */
preferIPv6Address
= (*env)->GetStaticIntField(env, ia_class, ia_preferIPv6AddressID);
/* Try once, with our static buffer. */
// try once, with our static buffer
memset(&hints, 0, sizeof(hints));
hints.ai_flags = AI_CANONNAME;
hints.ai_family = AF_UNSPEC;
@ -82,35 +81,28 @@ Java_java_net_Inet6AddressImpl_lookupAllHostAddr(JNIEnv *env, jobject this,
error = getaddrinfo(hostname, NULL, &hints, &res);
if (error) {
if (WSAGetLastError() == WSATRY_AGAIN) {
NET_ThrowByNameWithLastError(env,
JNU_JAVANETPKG "UnknownHostException",
hostname);
JNU_ReleaseStringPlatformChars(env, host, hostname);
return NULL;
} else {
/* report error */
JNU_ThrowByName(env, JNU_JAVANETPKG "UnknownHostException",
(char *)hostname);
JNU_ReleaseStringPlatformChars(env, host, hostname);
return NULL;
}
// report error
NET_ThrowByNameWithLastError(env, "java/net/UnknownHostException",
hostname);
goto cleanupAndReturn;
} else {
int i = 0;
int inetCount = 0, inet6Count = 0, inetIndex = 0, inet6Index = 0, originalIndex = 0;
struct addrinfo *itr, *last, *iterator = res;
int i = 0, inetCount = 0, inet6Count = 0, inetIndex = 0,
inet6Index = 0, originalIndex = 0;
int addressPreference =
(*env)->GetStaticIntField(env, ia_class, ia_preferIPv6AddressID);
iterator = res;
while (iterator != NULL) {
// skip duplicates
int skip = 0;
itr = resNew;
while (itr != NULL) {
if (iterator->ai_family == itr->ai_family &&
iterator->ai_addrlen == itr->ai_addrlen) {
if (itr->ai_family == AF_INET) { /* AF_INET */
struct addrinfo *iteratorNew = resNew;
while (iteratorNew != NULL) {
if (iterator->ai_family == iteratorNew->ai_family &&
iterator->ai_addrlen == iteratorNew->ai_addrlen) {
if (iteratorNew->ai_family == AF_INET) { /* AF_INET */
struct sockaddr_in *addr1, *addr2;
addr1 = (struct sockaddr_in *)iterator->ai_addr;
addr2 = (struct sockaddr_in *)itr->ai_addr;
if (addr1->sin_addr.s_addr ==
addr2->sin_addr.s_addr) {
addr2 = (struct sockaddr_in *)iteratorNew->ai_addr;
if (addr1->sin_addr.s_addr == addr2->sin_addr.s_addr) {
skip = 1;
break;
}
@ -118,7 +110,7 @@ Java_java_net_Inet6AddressImpl_lookupAllHostAddr(JNIEnv *env, jobject this,
int t;
struct sockaddr_in6 *addr1, *addr2;
addr1 = (struct sockaddr_in6 *)iterator->ai_addr;
addr2 = (struct sockaddr_in6 *)itr->ai_addr;
addr2 = (struct sockaddr_in6 *)iteratorNew->ai_addr;
for (t = 0; t < 16; t++) {
if (addr1->sin6_addr.s6_addr[t] !=
@ -127,7 +119,7 @@ Java_java_net_Inet6AddressImpl_lookupAllHostAddr(JNIEnv *env, jobject this,
}
}
if (t < 16) {
itr = itr->ai_next;
iteratorNew = iteratorNew->ai_next;
continue;
} else {
skip = 1;
@ -136,16 +128,16 @@ Java_java_net_Inet6AddressImpl_lookupAllHostAddr(JNIEnv *env, jobject this,
}
} else if (iterator->ai_family != AF_INET &&
iterator->ai_family != AF_INET6) {
/* we can't handle other family types */
// we can't handle other family types
skip = 1;
break;
}
itr = itr->ai_next;
iteratorNew = iteratorNew->ai_next;
}
if (!skip) {
struct addrinfo *next
= (struct addrinfo*) malloc(sizeof(struct addrinfo));
= (struct addrinfo *)malloc(sizeof(struct addrinfo));
if (!next) {
JNU_ThrowOutOfMemoryError(env, "Native heap allocation failed");
ret = NULL;
@ -161,87 +153,81 @@ Java_java_net_Inet6AddressImpl_lookupAllHostAddr(JNIEnv *env, jobject this,
last = next;
i++;
if (iterator->ai_family == AF_INET) {
inetCount ++;
inetCount++;
} else if (iterator->ai_family == AF_INET6) {
inet6Count ++;
inet6Count++;
}
}
iterator = iterator->ai_next;
}
retLen = i;
iterator = resNew;
i = 0;
ret = (*env)->NewObjectArray(env, retLen, ia_class, NULL);
// allocate array - at this point i contains the number of addresses
ret = (*env)->NewObjectArray(env, i, ia_class, NULL);
if (IS_NULL(ret)) {
/* we may have memory to free at the end of this */
goto cleanupAndReturn;
}
if (preferIPv6Address == java_net_InetAddress_PREFER_IPV6_VALUE) {
if (addressPreference == java_net_InetAddress_PREFER_IPV6_VALUE) {
inetIndex = inet6Count;
inet6Index = 0;
} else if (preferIPv6Address == java_net_InetAddress_PREFER_IPV4_VALUE) {
} else if (addressPreference == java_net_InetAddress_PREFER_IPV4_VALUE) {
inetIndex = 0;
inet6Index = inetCount;
} else if (preferIPv6Address == java_net_InetAddress_PREFER_SYSTEM_VALUE) {
} else if (addressPreference == java_net_InetAddress_PREFER_SYSTEM_VALUE) {
inetIndex = inet6Index = originalIndex = 0;
}
iterator = resNew;
while (iterator != NULL) {
if (iterator->ai_family == AF_INET) {
jobject iaObj = (*env)->NewObject(env, ia4_class, ia4_ctrID);
if (IS_NULL(iaObj)) {
ret = NULL;
goto cleanupAndReturn;
}
setInetAddress_addr(env, iaObj, ntohl(((struct sockaddr_in*)iterator->ai_addr)->sin_addr.s_addr));
setInetAddress_hostName(env, iaObj, host);
(*env)->SetObjectArrayElement(env, ret, (inetIndex | originalIndex), iaObj);
inetIndex ++;
jobject iaObj = (*env)->NewObject(env, ia4_class, ia4_ctrID);
if (IS_NULL(iaObj)) {
ret = NULL;
goto cleanupAndReturn;
}
setInetAddress_addr(env, iaObj, ntohl(((struct sockaddr_in*)iterator->ai_addr)->sin_addr.s_addr));
setInetAddress_hostName(env, iaObj, host);
(*env)->SetObjectArrayElement(env, ret, (inetIndex | originalIndex), iaObj);
inetIndex++;
} else if (iterator->ai_family == AF_INET6) {
jint scope = 0;
jboolean ret1;
jobject iaObj = (*env)->NewObject(env, ia6_class, ia6_ctrID);
if (IS_NULL(iaObj)) {
ret = NULL;
goto cleanupAndReturn;
}
ret1 = setInet6Address_ipaddress(env, iaObj, (jbyte *)&(((struct sockaddr_in6*)iterator->ai_addr)->sin6_addr));
if (ret1 == JNI_FALSE) {
ret = NULL;
goto cleanupAndReturn;
}
scope = ((struct sockaddr_in6*)iterator->ai_addr)->sin6_scope_id;
if (scope != 0) { /* zero is default value, no need to set */
setInet6Address_scopeid(env, iaObj, scope);
}
setInetAddress_hostName(env, iaObj, host);
(*env)->SetObjectArrayElement(env, ret, (inet6Index | originalIndex), iaObj);
inet6Index ++;
jint scope = 0;
jboolean ret1;
jobject iaObj = (*env)->NewObject(env, ia6_class, ia6_ctrID);
if (IS_NULL(iaObj)) {
ret = NULL;
goto cleanupAndReturn;
}
ret1 = setInet6Address_ipaddress(env, iaObj, (char *)&(((struct sockaddr_in6*)iterator->ai_addr)->sin6_addr));
if (ret1 == JNI_FALSE) {
ret = NULL;
goto cleanupAndReturn;
}
scope = ((struct sockaddr_in6 *)iterator->ai_addr)->sin6_scope_id;
if (scope != 0) { // zero is default value, no need to set
setInet6Address_scopeid(env, iaObj, scope);
}
setInetAddress_hostName(env, iaObj, host);
(*env)->SetObjectArrayElement(env, ret, (inet6Index | originalIndex), iaObj);
inet6Index++;
}
if (preferIPv6Address == java_net_InetAddress_PREFER_SYSTEM_VALUE) {
if (addressPreference == java_net_InetAddress_PREFER_SYSTEM_VALUE) {
originalIndex++;
inetIndex = inet6Index = 0;
}
iterator = iterator->ai_next;
}
}
cleanupAndReturn:
{
struct addrinfo *iterator, *tmp;
iterator = resNew;
while (iterator != NULL) {
tmp = iterator;
iterator = iterator->ai_next;
free(tmp);
}
JNU_ReleaseStringPlatformChars(env, host, hostname);
JNU_ReleaseStringPlatformChars(env, host, hostname);
while (resNew != NULL) {
last = resNew;
resNew = resNew->ai_next;
free(last);
}
if (res != NULL) {
freeaddrinfo(res);
}
freeaddrinfo(res);
return ret;
}
@ -249,57 +235,48 @@ cleanupAndReturn:
* Class: java_net_Inet6AddressImpl
* Method: getHostByAddr
* Signature: (I)Ljava/lang/String;
*
* Theoretically the UnknownHostException could be enriched with gai error
* information. But as it is silently ignored anyway, there's no need for this.
* It's only important that either a valid hostname is returned or an
* UnknownHostException is thrown.
*/
JNIEXPORT jstring JNICALL
Java_java_net_Inet6AddressImpl_getHostByAddr(JNIEnv *env, jobject this,
jbyteArray addrArray) {
jbyteArray addrArray) {
jstring ret = NULL;
char host[NI_MAXHOST+1];
int error = 0;
char host[NI_MAXHOST + 1];
int len = 0;
jbyte caddr[16];
SOCKETADDRESS sa;
struct sockaddr_in him4;
struct sockaddr_in6 him6;
struct sockaddr *sa;
memset((void *)&sa, 0, sizeof(SOCKETADDRESS));
/*
* For IPv4 addresses construct a sockaddr_in structure.
*/
// construct a sockaddr_in structure (AF_INET or AF_INET6)
if ((*env)->GetArrayLength(env, addrArray) == 4) {
jint addr;
(*env)->GetByteArrayRegion(env, addrArray, 0, 4, caddr);
addr = ((caddr[0]<<24) & 0xff000000);
addr |= ((caddr[1] <<16) & 0xff0000);
addr |= ((caddr[2] <<8) & 0xff00);
addr = ((caddr[0] << 24) & 0xff000000);
addr |= ((caddr[1] << 16) & 0xff0000);
addr |= ((caddr[2] << 8) & 0xff00);
addr |= (caddr[3] & 0xff);
memset((char *) &him4, 0, sizeof(him4));
him4.sin_addr.s_addr = htonl(addr);
him4.sin_family = AF_INET;
sa = (struct sockaddr *) &him4;
len = sizeof(him4);
sa.sa4.sin_addr.s_addr = htonl(addr);
sa.sa4.sin_family = AF_INET;
len = sizeof(struct sockaddr_in);
} else {
/*
* For IPv6 address construct a sockaddr_in6 structure.
*/
(*env)->GetByteArrayRegion(env, addrArray, 0, 16, caddr);
memset((char *) &him6, 0, sizeof(him6));
memcpy((void *)&(him6.sin6_addr), caddr, sizeof(struct in6_addr) );
him6.sin6_family = AF_INET6;
sa = (struct sockaddr *) &him6 ;
len = sizeof(him6) ;
memcpy((void *)&sa.sa6.sin6_addr, caddr, sizeof(struct in6_addr));
sa.sa6.sin6_family = AF_INET6;
len = sizeof(struct sockaddr_in6);
}
error = getnameinfo(sa, len, host, NI_MAXHOST, NULL, 0, NI_NAMEREQD);
if (!error) {
if (getnameinfo(&sa.sa, len, host, NI_MAXHOST, NULL, 0, NI_NAMEREQD)) {
JNU_ThrowByName(env, "java/net/UnknownHostException", NULL);
} else {
ret = (*env)->NewStringUTF(env, host);
CHECK_NULL_RETURN(ret, NULL);
}
if (ret == NULL) {
JNU_ThrowByName(env, JNU_JAVANETPKG "UnknownHostException", NULL);
if (ret == NULL) {
JNU_ThrowByName(env, "java/net/UnknownHostException", NULL);
}
}
return ret;
@ -309,99 +286,82 @@ Java_java_net_Inet6AddressImpl_getHostByAddr(JNIEnv *env, jobject this,
* ping implementation using tcp port 7 (echo)
*/
static jboolean
tcp_ping6(JNIEnv *env,
jint timeout,
jint ttl,
struct sockaddr_in6 him6,
struct sockaddr_in6* netif,
int len)
tcp_ping6(JNIEnv *env, SOCKETADDRESS *sa, SOCKETADDRESS *netif, jint timeout,
jint ttl)
{
jint fd;
WSAEVENT hEvent;
int connect_rv = -1;
WSAEVENT hEvent;
// open a TCP socket
fd = NET_Socket(AF_INET6, SOCK_STREAM, 0);
if (fd == SOCKET_ERROR) {
/* note: if you run out of fds, you may not be able to load
* the exception class, and get a NoClassDefFoundError
* instead.
*/
NET_ThrowNew(env, errno, "Can't create socket");
// note: if you run out of fds, you may not be able to load
// the exception class, and get a NoClassDefFoundError instead.
NET_ThrowNew(env, WSAGetLastError(), "Can't create socket");
return JNI_FALSE;
}
/**
* A TTL was specified, let's set the socket option.
*/
// set TTL
if (ttl > 0) {
setsockopt(fd, IPPROTO_IPV6, IPV6_UNICAST_HOPS, (const char *)&ttl, sizeof(ttl));
setsockopt(fd, IPPROTO_IPV6, IPV6_UNICAST_HOPS, (const char *)&ttl, sizeof(ttl));
}
/**
* A network interface was specified, let's bind to it.
*/
// A network interface was specified, so let's bind to it.
if (netif != NULL) {
if (NET_Bind(fd, (struct sockaddr*)netif, sizeof(struct sockaddr_in6)) < 0) {
NET_ThrowNew(env, WSAGetLastError(), "Can't bind socket to interface");
closesocket(fd);
return JNI_FALSE;
}
if (bind(fd, &netif->sa, sizeof(struct sockaddr_in6)) < 0) {
NET_ThrowNew(env, WSAGetLastError(), "Can't bind socket to interface");
closesocket(fd);
return JNI_FALSE;
}
}
/**
* Make the socket non blocking.
*/
// Make the socket non blocking so we can use select/poll.
hEvent = WSACreateEvent();
WSAEventSelect(fd, hEvent, FD_READ|FD_CONNECT|FD_CLOSE);
/* no need to use NET_Connect as non-blocking */
him6.sin6_port = htons((short) 7); /* Echo port */
connect_rv = connect(fd, (struct sockaddr *)&him6, len);
sa->sa6.sin6_port = htons(7); // echo port
connect_rv = connect(fd, &sa->sa, sizeof(struct sockaddr_in6));
/**
* connection established or refused immediately, either way it means
* we were able to reach the host!
*/
// connection established or refused immediately, either way it means
// we were able to reach the host!
if (connect_rv == 0 || WSAGetLastError() == WSAECONNREFUSED) {
WSACloseEvent(hEvent);
closesocket(fd);
return JNI_TRUE;
} else {
int optlen;
}
switch (WSAGetLastError()) {
case WSAEHOSTUNREACH: /* Host Unreachable */
case WSAENETUNREACH: /* Network Unreachable */
case WSAENETDOWN: /* Network is down */
case WSAEPFNOSUPPORT: /* Protocol Family unsupported */
WSACloseEvent(hEvent);
closesocket(fd);
return JNI_FALSE;
}
switch (WSAGetLastError()) {
case WSAEHOSTUNREACH: // Host Unreachable
case WSAENETUNREACH: // Network Unreachable
case WSAENETDOWN: // Network is down
case WSAEPFNOSUPPORT: // Protocol Family unsupported
WSACloseEvent(hEvent);
closesocket(fd);
return JNI_FALSE;
case WSAEWOULDBLOCK: // this is expected as we'll probably have to wait
break;
default:
NET_ThrowByNameWithLastError(env, JNU_JAVANETPKG "ConnectException",
"connect failed");
WSACloseEvent(hEvent);
closesocket(fd);
return JNI_FALSE;
}
if (WSAGetLastError() != WSAEWOULDBLOCK) {
NET_ThrowByNameWithLastError(env, JNU_JAVANETPKG "ConnectException",
"connect failed");
WSACloseEvent(hEvent);
closesocket(fd);
return JNI_FALSE;
}
timeout = NET_Wait(env, fd, NET_WAIT_CONNECT, timeout);
if (timeout >= 0) {
/* has connection been established? */
optlen = sizeof(connect_rv);
if (getsockopt(fd, SOL_SOCKET, SO_ERROR, (void*)&connect_rv,
&optlen) <0) {
timeout = NET_Wait(env, fd, NET_WAIT_CONNECT, timeout);
if (timeout >= 0) {
// connection has been established, check for error condition
int optlen = sizeof(connect_rv);
if (getsockopt(fd, SOL_SOCKET, SO_ERROR, (void *)&connect_rv,
&optlen) < 0)
{
connect_rv = WSAGetLastError();
}
if (connect_rv == 0 || connect_rv == WSAECONNREFUSED) {
}
if (connect_rv == 0 || connect_rv == WSAECONNREFUSED) {
WSACloseEvent(hEvent);
closesocket(fd);
return JNI_TRUE;
}
}
}
WSACloseEvent(hEvent);
@ -416,21 +376,18 @@ tcp_ping6(JNIEnv *env,
* Returns true is an ECHO_REPLY is received, otherwise, false.
*/
static jboolean
ping6(JNIEnv *env,
struct sockaddr_in6* src,
struct sockaddr_in6* dest,
jint timeout,
HANDLE hIcmpFile)
ping6(JNIEnv *env, HANDLE hIcmpFile, SOCKETADDRESS *sa,
SOCKETADDRESS *netif, jint timeout)
{
DWORD dwRetVal = 0;
char SendData[32] = {0};
LPVOID ReplyBuffer = NULL;
DWORD ReplySize = 0;
IP_OPTION_INFORMATION ipInfo = {255, 0, 0, 0, NULL};
struct sockaddr_in6 sa6Source;
SOCKETADDRESS dftNetif;
ReplySize = sizeof(ICMPV6_ECHO_REPLY) + sizeof(SendData);
ReplyBuffer = (VOID*) malloc(ReplySize);
ReplyBuffer = (VOID *)malloc(ReplySize);
if (ReplyBuffer == NULL) {
IcmpCloseHandle(hIcmpFile);
NET_ThrowNew(env, WSAGetLastError(), "Unable to allocate memory");
@ -438,17 +395,20 @@ ping6(JNIEnv *env,
}
//define local source information
sa6Source.sin6_addr = in6addr_any;
sa6Source.sin6_family = AF_INET6;
sa6Source.sin6_flowinfo = 0;
sa6Source.sin6_port = 0;
if (netif == NULL) {
dftNetif.sa6.sin6_addr = in6addr_any;
dftNetif.sa6.sin6_family = AF_INET6;
dftNetif.sa6.sin6_flowinfo = 0;
dftNetif.sa6.sin6_port = 0;
netif = &dftNetif;
}
dwRetVal = Icmp6SendEcho2(hIcmpFile, // HANDLE IcmpHandle,
NULL, // HANDLE Event,
NULL, // PIO_APC_ROUTINE ApcRoutine,
NULL, // PVOID ApcContext,
&sa6Source, // struct sockaddr_in6 *SourceAddress,
dest, // struct sockaddr_in6 *DestinationAddress,
&netif->sa6, // struct sockaddr_in6 *SourceAddress,
&sa->sa6, // struct sockaddr_in6 *DestinationAddress,
SendData, // LPVOID RequestData,
sizeof(SendData), // WORD RequestSize,
&ipInfo, // PIP_OPTION_INFORMATION RequestOptions,
@ -459,11 +419,10 @@ ping6(JNIEnv *env,
free(ReplyBuffer);
IcmpCloseHandle(hIcmpFile);
if (dwRetVal != 0) {
return JNI_TRUE;
} else {
if (dwRetVal == 0) { // if the call failed
return JNI_FALSE;
} else {
return JNI_TRUE;
}
}
@ -474,75 +433,64 @@ ping6(JNIEnv *env,
*/
JNIEXPORT jboolean JNICALL
Java_java_net_Inet6AddressImpl_isReachable0(JNIEnv *env, jobject this,
jbyteArray addrArray,
jint scope,
jint timeout,
jbyteArray ifArray,
jint ttl, jint if_scope) {
jbyteArray addrArray, jint scope,
jint timeout, jbyteArray ifArray,
jint ttl, jint if_scope)
{
jbyte caddr[16];
jint sz;
struct sockaddr_in6 him6;
struct sockaddr_in6* netif = NULL;
struct sockaddr_in6 inf6;
int len = 0;
SOCKETADDRESS sa, inf, *netif = NULL;
HANDLE hIcmpFile;
/*
* If IPv6 is not enable, then we can't reach an IPv6 address, can we?
* Actually, we probably shouldn't even get here.
*/
// If IPv6 is not enabled, then we can't reach an IPv6 address, can we?
// Actually, we probably shouldn't even get here.
if (!ipv6_available()) {
return JNI_FALSE;
return JNI_FALSE;
}
/*
* If it's an IPv4 address, ICMP won't work with IPv4 mapped address,
* therefore, let's delegate to the Inet4Address method.
*/
// If it's an IPv4 address, ICMP won't work with IPv4 mapped address,
// therefore, let's delegate to the Inet4Address method.
sz = (*env)->GetArrayLength(env, addrArray);
if (sz == 4) {
return Java_java_net_Inet4AddressImpl_isReachable0(env, this,
addrArray,
timeout,
ifArray, ttl);
return Java_java_net_Inet4AddressImpl_isReachable0(env, this,
addrArray, timeout,
ifArray, ttl);
}
memset((char *) caddr, 0, 16);
memset((char *) &him6, 0, sizeof(him6));
// load address to SOCKETADDRESS
memset((char *)caddr, 0, 16);
(*env)->GetByteArrayRegion(env, addrArray, 0, 16, caddr);
memcpy((void *)&(him6.sin6_addr), caddr, sizeof(struct in6_addr) );
him6.sin6_family = AF_INET6;
memset((char *)&sa, 0, sizeof(SOCKETADDRESS));
memcpy((void *)&sa.sa6.sin6_addr, caddr, sizeof(struct in6_addr));
sa.sa6.sin6_family = AF_INET6;
if (scope > 0) {
him6.sin6_scope_id = scope;
sa.sa6.sin6_scope_id = scope;
}
len = sizeof(struct sockaddr_in6);
/**
* A network interface was specified, let's convert the address
*/
// load network interface address to SOCKETADDRESS, if specified
if (!(IS_NULL(ifArray))) {
memset((char *) caddr, 0, 16);
memset((char *) &inf6, 0, sizeof(inf6));
(*env)->GetByteArrayRegion(env, ifArray, 0, 16, caddr);
memcpy((void *)&(inf6.sin6_addr), caddr, sizeof(struct in6_addr) );
inf6.sin6_family = AF_INET6;
inf6.sin6_port = 0;
inf6.sin6_scope_id = if_scope;
netif = &inf6;
memset((char *)caddr, 0, 16);
(*env)->GetByteArrayRegion(env, ifArray, 0, 16, caddr);
memset((char *)&inf, 0, sizeof(SOCKETADDRESS));
memcpy((void *)&inf.sa6.sin6_addr, caddr, sizeof(struct in6_addr));
inf.sa6.sin6_family = AF_INET6;
inf.sa6.sin6_scope_id = if_scope;
netif = &inf;
}
// Let's try to create an ICMP handle.
hIcmpFile = Icmp6CreateFile();
if (hIcmpFile == INVALID_HANDLE_VALUE) {
int err = WSAGetLastError();
if (err == ERROR_ACCESS_DENIED) {
// fall back to TCP echo if access is denied to ICMP
return tcp_ping6(env, timeout, ttl, him6, netif, len);
return tcp_ping6(env, &sa, netif, timeout, ttl);
} else {
NET_ThrowNew(env, err, "Unable to create ICMP file handle");
return JNI_FALSE;
}
} else {
return ping6(env, netif, &him6, timeout, hIcmpFile);
// It didn't fail, so we can use ICMP.
return ping6(env, hIcmpFile, &sa, netif, timeout);
}
return JNI_FALSE;
}

View File

@ -259,6 +259,11 @@ tools/jimage/JImageVerifyTest.java 8170120 generic-
tools/jlink/multireleasejar/JLinkMultiReleaseJarTest.java 8169971 windows-x64
tools/jar/multiRelease/RuntimeTest.java 8173905 generic-all
tools/schemagen/MultiReleaseJarTest.java 8174692 generic-all
tools/wsgen/MultiReleaseJarTest.java 8174692 generic-all
############################################################################
# jdk_jdi

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2013, 2016, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2013, 2017, 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
@ -62,7 +62,7 @@ public class CheckOrigin {
ProcessBuilder pb = ProcessTools.
createJavaProcessBuilder(
"--add-exports", "jdk.attach/sun.tools.attach=ALL-UNNAMED",
"-XX:+UseConcMarkSweepGC", // this will cause UseParNewGC to be FLAG_SET_ERGO
"-XX:+UseConcMarkSweepGC", // this will cause MaxNewSize to be FLAG_SET_ERGO
"-XX:+UseCodeAging",
"-XX:+UseCerealGC", // Should be ignored.
"-XX:Flags=" + flagsFile.getAbsolutePath(),
@ -109,7 +109,7 @@ public class CheckOrigin {
// Set through j.l.m
checkOrigin("HeapDumpOnOutOfMemoryError", Origin.MANAGEMENT);
// Should be set by the VM, when we set UseConcMarkSweepGC
checkOrigin("UseParNewGC", Origin.ERGONOMIC);
checkOrigin("MaxNewSize", Origin.ERGONOMIC);
// Set using attach
checkOrigin("HeapDumpPath", Origin.ATTACH_ON_DEMAND);
}

View File

@ -82,9 +82,9 @@ public final class LFGarbageCollectedTest extends LambdaFormTestCase {
throw new Error("Unexpected error: Lambda form of the method handle is null");
}
String debugName = (String)DEBUG_NAME.get(lambdaForm);
if (debugName != null && debugName.startsWith("identity_")) {
// Ignore identity_* LambdaForms.
String kind = KIND_FIELD.get(lambdaForm).toString();
if (kind.equals("IDENTITY")) {
// Ignore identity LambdaForms.
return;
}

View File

@ -51,7 +51,7 @@ public abstract class LambdaFormTestCase {
* used to get a lambda form from a method handle.
*/
protected static final Method INTERNAL_FORM;
protected static final Field DEBUG_NAME;
protected static final Field KIND_FIELD;
protected static final Field REF_FIELD;
private static final List<GarbageCollectorMXBean> gcInfo;
@ -64,8 +64,8 @@ public abstract class LambdaFormTestCase {
INTERNAL_FORM = MethodHandle.class.getDeclaredMethod("internalForm");
INTERNAL_FORM.setAccessible(true);
DEBUG_NAME = Class.forName("java.lang.invoke.LambdaForm").getDeclaredField("debugName");
DEBUG_NAME.setAccessible(true);
KIND_FIELD = Class.forName("java.lang.invoke.LambdaForm").getDeclaredField("kind");
KIND_FIELD.setAccessible(true);
REF_FIELD = Reference.class.getDeclaredField("referent");
REF_FIELD.setAccessible(true);

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2003, 2016, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2003, 2017, 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
@ -36,7 +36,6 @@
* @run main/timeout=600 LowMemoryTest
* @requires vm.gc == "null"
* @requires vm.opt.ExplicitGCInvokesConcurrent != "true"
* @requires vm.opt.ExplicitGCInvokesConcurrentAndUnloadsClasses != "true"
* @requires vm.opt.DisableExplicitGC != "true"
*/

View File

@ -1,5 +1,5 @@
#
# Copyright (c) 2004, 2015, Oracle and/or its affiliates. All rights reserved.
# Copyright (c) 2004, 2017, 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
@ -53,12 +53,12 @@ go() {
# Run test with each GC configuration
#
# Notes: To ensure that metaspace fills up we disable class unloading.
# Also we set the max metaspace to 8MB - otherwise the test takes too
# Also we set the max metaspace to 16MB - otherwise the test takes too
# long to run.
go -noclassgc -XX:MaxMetaspaceSize=16m -XX:+UseSerialGC LowMemoryTest2
go -noclassgc -XX:MaxMetaspaceSize=16m -XX:+UseParallelGC LowMemoryTest2
go -noclassgc -XX:MaxMetaspaceSize=16m -XX:+UseParNewGC -XX:+UseConcMarkSweepGC LowMemoryTest2
go -noclassgc -XX:MaxMetaspaceSize=16m -XX:+UseConcMarkSweepGC LowMemoryTest2
# Test class metaspace - might hit MaxMetaspaceSize instead if
# UseCompressedClassPointers is off or if 32 bit.

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2003, 2016, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2003, 2017, 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
@ -37,7 +37,6 @@
* @build jdk.testlibrary.* ResetPeakMemoryUsage MemoryUtil RunUtil
* @run main ResetPeakMemoryUsage
* @requires vm.opt.ExplicitGCInvokesConcurrent != "true"
* @requires vm.opt.ExplicitGCInvokesConcurrentAndUnloadsClasses != "true"
* @requires vm.opt.DisableExplicitGC != "true"
*/

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2016, 2017, 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

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2013, 2015, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2013, 2017, 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
@ -42,7 +42,7 @@ public class ProviderVersionCheck {
for (Provider p: Security.getProviders()) {
System.out.print(p.getName() + " ");
if (p.getVersion() != 9.0d) {
if (p.getVersion() != 10.0d) {
System.out.println("failed. " + "Version received was " +
p.getVersion());
failure = true;

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2016, 2017, 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
@ -74,7 +74,8 @@ public class MVJarSigningTest {
private static final String KEYPASS = "changeit";
private static final String SIGNED_JAR = "Signed.jar";
private static final String POLICY_FILE = "SignedJar.policy";
private static final String VERSION_MESSAGE = "I am running on version 9";
private static final String VERSION = "" + Runtime.version().major();
private static final String VERSION_MESSAGE = "I am running on version " + VERSION;
public static void main(String[] args) throws Throwable {
// compile java files in jarContent directory

View File

@ -396,5 +396,7 @@ e5a42ddaf633fde14b983f740ae0e7e490741fd1 jdk-9+150
4f348bd05341581df84ff1510d5b3a9b5b488367 jdk-9+151
5b6f12de6f9167a582fa2c6ac54e69c591b09e68 jdk-9+152
03f48cd283f5dd6b7153fd7e0cf2df8582b14391 jdk-9+153
b670e95106f5327a29e2e2c4f18ee48a8d36e481 jdk-10+0
6a9dd3d893b0a493a3e5d8d392815b5ee76a02d9 jdk-9+154
dfcfdb2db85f1bb434209f56ca557ea6f9830aa8 jdk-9+155
6f91e41163bc09e9b3ec72e8d1185f39296ee5d4 jdk-9+156

View File

@ -1 +1 @@
project=jdk9
project=jdk10

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2005, 2016, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2005, 2017, 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
@ -56,6 +56,7 @@ public enum SourceVersion {
* 1.7: diamond syntax, try-with-resources, etc.
* 1.8: lambda expressions and default methods
* 9: modules, small cleanups to 1.7 and 1.8 changes
* 10: to-be-determined changes
*/
/**
@ -150,7 +151,15 @@ public enum SourceVersion {
*
* @since 9
*/
RELEASE_9;
RELEASE_9,
/**
* The version recognized by the Java Platform, Standard Edition
* 10.
*
* @since 10
*/
RELEASE_10;
// Note that when adding constants for newer releases, the
// behavior of latest() and latestSupported() must be updated too.
@ -161,7 +170,7 @@ public enum SourceVersion {
* @return the latest source version that can be modeled
*/
public static SourceVersion latest() {
return RELEASE_9;
return RELEASE_10;
}
private static final SourceVersion latestSupported = getLatestSupported();
@ -171,6 +180,8 @@ public enum SourceVersion {
String specVersion = System.getProperty("java.specification.version");
switch (specVersion) {
case "10":
return RELEASE_10;
case "9":
case "1.9":
return RELEASE_9;

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2002, 2015, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2002, 2017, 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
@ -70,8 +70,11 @@ public enum Source {
/** 1.8 lambda expressions and default methods. */
JDK1_8("1.8"),
/** 1.9 covers the to be determined language features that will be added in JDK 9. */
JDK1_9("1.9");
/** 1.9 modularity. */
JDK1_9("1.9"),
/** 1.10 covers the to be determined language features that will be added in JDK 10. */
JDK1_10("1.10");
private static final Context.Key<Source> sourceKey = new Context.Key<>();
@ -99,6 +102,7 @@ public enum Source {
tab.put("7", JDK1_7); // Make 7 an alias for 1.7
tab.put("8", JDK1_8); // Make 8 an alias for 1.8
tab.put("9", JDK1_9); // Make 9 an alias for 1.9
tab.put("10", JDK1_10); // Make 10 an alias for 1.10
}
private Source(String name) {
@ -116,6 +120,7 @@ public enum Source {
}
public Target requiredTarget() {
if (this.compareTo(JDK1_10) >= 0) return Target.JDK1_10;
if (this.compareTo(JDK1_9) >= 0) return Target.JDK1_9;
if (this.compareTo(JDK1_8) >= 0) return Target.JDK1_8;
if (this.compareTo(JDK1_7) >= 0) return Target.JDK1_7;
@ -240,6 +245,8 @@ public enum Source {
return RELEASE_8;
case JDK1_9:
return RELEASE_9;
case JDK1_10:
return RELEASE_10;
default:
return null;
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2002, 2013, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2002, 2017, 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
@ -40,9 +40,9 @@ import static com.sun.tools.javac.main.Option.PROFILE;
* deletion without notice.</b>
*/
public enum Profile {
COMPACT1("compact1", 1, Target.JDK1_8, Target.JDK1_9),
COMPACT2("compact2", 2, Target.JDK1_8, Target.JDK1_9),
COMPACT3("compact3", 3, Target.JDK1_8, Target.JDK1_9),
COMPACT1("compact1", 1, Target.JDK1_8, Target.JDK1_9, Target.JDK1_10),
COMPACT2("compact2", 2, Target.JDK1_8, Target.JDK1_9, Target.JDK1_10),
COMPACT3("compact3", 3, Target.JDK1_8, Target.JDK1_9, Target.JDK1_10),
DEFAULT {
@Override

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2002, 2016, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2002, 2017, 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
@ -61,7 +61,10 @@ public enum Target {
JDK1_8("1.8", 52, 0),
/** JDK 9. */
JDK1_9("1.9", 53, 0);
JDK1_9("1.9", 53, 0),
/** JDK 10, initially an alias for 9 */
JDK1_10("1.10", 53, 0);
private static final Context.Key<Target> targetKey = new Context.Key<>();
@ -91,6 +94,7 @@ public enum Target {
tab.put("7", JDK1_7);
tab.put("8", JDK1_8);
tab.put("9", JDK1_9);
tab.put("10", JDK1_10);
}
public final String name;
@ -102,7 +106,7 @@ public enum Target {
this.minorVersion = minorVersion;
}
public static final Target DEFAULT = JDK1_9;
public static final Target DEFAULT = values()[values().length - 1];
public static Target lookup(String name) {
return tab.get(name);
@ -146,5 +150,4 @@ public enum Target {
public String multiReleaseValue() {
return Integer.toString(this.ordinal() - Target.JDK1_1.ordinal() + 1);
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2014, 2017, 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
@ -90,6 +90,8 @@ public class JDKPlatformProvider implements PlatformProvider {
} catch (IOException | ProviderNotFoundException ex) {
}
}
// Workaround until full support for --release 9 distinct from --release 10
SUPPORTED_JAVA_PLATFORM_VERSIONS.add(targetNumericVersion(Target.JDK1_9));
SUPPORTED_JAVA_PLATFORM_VERSIONS.add(targetNumericVersion(Target.DEFAULT));
}
@ -108,7 +110,9 @@ public class JDKPlatformProvider implements PlatformProvider {
@Override
public Collection<Path> getPlatformPath() {
if (Target.lookup(version) == Target.DEFAULT) {
// Comparison should be == Target.DEFAULT once --release 9
// is distinct from 10
if (Target.lookup(version).compareTo(Target.JDK1_9) >= 0) {
return null;
}

View File

@ -55,7 +55,7 @@ import com.sun.tools.javac.util.StringUtils;
* deletion without notice.</b>
*/
@SupportedAnnotationTypes("*")
@SupportedSourceVersion(SourceVersion.RELEASE_9)
@SupportedSourceVersion(SourceVersion.RELEASE_10)
public class PrintingProcessor extends AbstractProcessor {
PrintWriter writer;

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2016, 2017, 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
@ -50,7 +50,7 @@ import javax.lang.model.util.Elements;
import javax.tools.Diagnostic;
import static javax.lang.model.SourceVersion.RELEASE_9;
import static javax.lang.model.SourceVersion.RELEASE_10;
/**
* Annotation processor for the Deprecation Scanner tool.
@ -58,7 +58,7 @@ import static javax.lang.model.SourceVersion.RELEASE_9;
*
*/
@SupportedAnnotationTypes("java.lang.Deprecated")
@SupportedSourceVersion(RELEASE_9)
@SupportedSourceVersion(RELEASE_10)
public class LoadProc extends AbstractProcessor {
Elements elements;
Messager messager;

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2016, 2017, 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
@ -101,7 +101,7 @@ public class Main implements DiagnosticListener<JavaFileObject> {
// Keep these updated manually until there's a compiler API
// that allows querying of supported releases.
final Set<String> releasesWithoutForRemoval = Set.of("6", "7", "8");
final Set<String> releasesWithForRemoval = Set.of("9");
final Set<String> releasesWithForRemoval = Set.of("9", "10");
final Set<String> validReleases;
{
@ -353,14 +353,14 @@ public class Main implements DiagnosticListener<JavaFileObject> {
* Process classes from a particular JDK release, using only information
* in this JDK.
*
* @param release "6", "7", "8", or "9"
* @param release "6", "7", "8", "9", or "10"
* @param classes collection of classes to process, may be empty
* @return success value
*/
boolean processRelease(String release, Collection<String> classes) throws IOException {
options.addAll(List.of("--release", release));
if (release.equals("9")) {
if (release.equals("9") || release.equals("10")) {
List<String> rootMods = List.of("java.se", "java.se.ee");
TraverseProc proc = new TraverseProc(rootMods);
JavaCompiler.CompilationTask task =
@ -484,7 +484,7 @@ public class Main implements DiagnosticListener<JavaFileObject> {
String dir = null;
String jar = null;
String jdkHome = null;
String release = "9";
String release = "10";
List<String> loadClasses = new ArrayList<>();
String csvFile = null;

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2005, 2015, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2005, 2017, 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
@ -52,7 +52,7 @@ public class T6265137 {
String srcdir = System.getProperty("test.src");
Iterable<? extends JavaFileObject> files =
fm.getJavaFileObjectsFromFiles(Arrays.asList(new File(srcdir, "T6265137a.java")));
javac.getTask(null, fm, dl, Arrays.asList("-target","9"), null, files).call();
javac.getTask(null, fm, dl, Arrays.asList("-target","10"), null, files).call();
}
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2006, 2015, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2006, 2017, 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
@ -23,7 +23,7 @@
/*
* @test
* @bug 6395981 6458819 7025784 8028543
* @bug 6395981 6458819 7025784 8028543 8028544
* @summary JavaCompilerTool and Tool must specify version of JLS and JVMS
* @author Peter von der Ah\u00e9
* @modules java.compiler
@ -31,7 +31,7 @@
* @run main/fail T6395981
* @run main/fail T6395981 RELEASE_3 RELEASE_5 RELEASE_6
* @run main/fail T6395981 RELEASE_0 RELEASE_1 RELEASE_2 RELEASE_3 RELEASE_4 RELEASE_5 RELEASE_6
* @run main T6395981 RELEASE_3 RELEASE_4 RELEASE_5 RELEASE_6 RELEASE_7 RELEASE_8 RELEASE_9
* @run main T6395981 RELEASE_3 RELEASE_4 RELEASE_5 RELEASE_6 RELEASE_7 RELEASE_8 RELEASE_9 RELEASE_10
*/
import java.util.EnumSet;

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2016, 2017, 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
@ -27,7 +27,8 @@
* @summary If an error is produced by an annotation processor, the code should not be Attred, \
* unless requested
* @modules jdk.compiler
* @compile StopAfterError.java
* @library /tools/javac/lib
* @build StopAfterError JavacTestingAbstractProcessor
* @compile/fail/ref=StopAfterError.out -XDrawDiagnostics -processor StopAfterError StopAfterErrorAux.java
* @compile/fail/ref=StopAfterError.out -XDshould-stop.ifError=PROCESS -XDrawDiagnostics -processor StopAfterError StopAfterErrorAux.java
* @compile/fail/ref=StopAfterErrorContinue.out -XDshould-stop.ifError=ATTR -XDrawDiagnostics -processor StopAfterError StopAfterErrorAux.java
@ -42,8 +43,7 @@ import javax.lang.model.SourceVersion;
import javax.lang.model.element.TypeElement;
import javax.tools.Diagnostic.Kind;
@SupportedAnnotationTypes("*")
public class StopAfterError extends AbstractProcessor {
public class StopAfterError extends JavacTestingAbstractProcessor {
@Override
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
@ -52,10 +52,4 @@ public class StopAfterError extends AbstractProcessor {
}
return false;
}
@Override
public SourceVersion getSupportedSourceVersion() {
return SourceVersion.latestSupported();
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2016, 2017, 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
@ -26,7 +26,8 @@
* @bug 8166700
* @summary Check that local classes originating in static initializer can be loaded properly.
* @modules jdk.compiler
* @build LocalTest$1Local LocalTest$2Local LocalTest$3Local LocalTest$4Local LocalTest$5Local LocalTest
* @library /tools/javac/lib
* @build LocalTest$1Local LocalTest$2Local LocalTest$3Local LocalTest$4Local LocalTest$5Local LocalTest JavacTestingAbstractProcessor
* @compile LocalClassesModel.java
* @compile/process/ref=LocalClassesModel.out -processor LocalClassesModel LocalTest$1Local LocalTest$2Local LocalTest$3Local LocalTest$4Local LocalTest$5Local LocalTest
*/
@ -42,8 +43,7 @@ import javax.lang.model.element.TypeElement;
import javax.lang.model.element.VariableElement;
import javax.lang.model.util.ElementFilter;
@SupportedAnnotationTypes("*")
public class LocalClassesModel extends AbstractProcessor {
public class LocalClassesModel extends JavacTestingAbstractProcessor {
@Override
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
@ -65,9 +65,4 @@ public class LocalClassesModel extends AbstractProcessor {
return false;
}
@Override
public SourceVersion getSupportedSourceVersion() {
return SourceVersion.latestSupported();
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2011, 2016, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2011, 2017, 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
@ -23,7 +23,7 @@
/*
* @test
* @bug 7025809 8028543 6415644
* @bug 7025809 8028543 6415644 8028544 8029942
* @summary Test latest, latestSupported, underscore as keyword, etc.
* @author Joseph D. Darcy
* @modules java.compiler
@ -44,8 +44,8 @@ public class TestSourceVersion {
}
private static void testLatestSupported() {
if (SourceVersion.latest() != RELEASE_9 ||
SourceVersion.latestSupported() != RELEASE_9)
if (SourceVersion.latest() != RELEASE_10 ||
SourceVersion.latestSupported() != RELEASE_10)
throw new RuntimeException("Unexpected release value(s) found:\n" +
"latest:\t" + SourceVersion.latest() + "\n" +
"latestSupported:\t" + SourceVersion.latestSupported());

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2016, 2017, 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
@ -24,7 +24,8 @@
/**
* @test
* @modules jdk.compiler
* @build NestedTypeVars
* @library /tools/javac/lib
* @build NestedTypeVars JavacTestingAbstractProcessor
* @compile/process/ref=NestedTypeVars.out -processor NestedTypeVars Test$1L1$L2$1L3$L4$L5 Test$1L1$CCheck Test$1L1 Test$1CCheck Test$CCheck Test
*/
@ -44,8 +45,7 @@ import javax.lang.model.type.TypeMirror;
import javax.lang.model.type.TypeVariable;
import javax.lang.model.util.ElementFilter;
@SupportedAnnotationTypes("*")
public class NestedTypeVars extends AbstractProcessor{
public class NestedTypeVars extends JavacTestingAbstractProcessor {
@Override
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
@ -102,12 +102,6 @@ public class NestedTypeVars extends AbstractProcessor{
throw new IllegalStateException("Unexpected element: " + el + "(" + el.getKind() + ")");
}
}
@Override
public SourceVersion getSupportedSourceVersion() {
return SourceVersion.latestSupported();
}
}
class Test<T1, C> {

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2006, 2015, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2006, 2017, 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
@ -35,6 +35,7 @@
* @compile/ref=gold_unsp_warn.out -XDrawDiagnostics -processor TestSourceVersionWarnings -proc:only -ASourceVersion=RELEASE_6 -source 1.6 -Xlint:-options -Aunsupported HelloWorld.java
* @compile/ref=gold_sv_none.out -XDrawDiagnostics -processor TestSourceVersionWarnings -proc:only -ASourceVersion=RELEASE_7 -source 1.7 -Xlint:-options HelloWorld.java
* @compile/ref=gold_sv_none.out -XDrawDiagnostics -processor TestSourceVersionWarnings -proc:only -ASourceVersion=RELEASE_8 -source 1.8 -Xlint:-options HelloWorld.java
* @compile/ref=gold_sv_none.out -XDrawDiagnostics -processor TestSourceVersionWarnings -proc:only -ASourceVersion=RELEASE_9 -source 1.9 -Xlint:-options HelloWorld.java
*/
import java.util.Set;

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2011, 2016, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2011, 2017, 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
@ -148,6 +148,7 @@ public class ProfileOptionTest {
error("unexpected exception from compiler: " + ise);
break;
case JDK1_9:
case JDK1_10:
if (p == Profile.DEFAULT)
break;
if (ise == null)

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2015, 2017, 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
@ -26,7 +26,8 @@
* @bug 8068737
* @summary Tests ArrayType.toString with type annotations present
* @modules jdk.compiler/com.sun.tools.javac.code
* @build ArrayTypeToString
* @library /tools/javac/lib
* @build ArrayTypeToString JavacTestingAbstractProcessor
* @compile/ref=ArrayTypeToString.out -XDaccessInternalAPI -XDrawDiagnostics -processor ArrayTypeToString -proc:only ArrayTypeToString.java
*/
@ -54,8 +55,7 @@ import com.sun.tools.javac.code.Symbol.VarSymbol;
}
@SupportedAnnotationTypes("Foo")
@SupportedSourceVersion(SourceVersion.RELEASE_9)
public class ArrayTypeToString extends AbstractProcessor {
public class ArrayTypeToString extends JavacTestingAbstractProcessor {
@Foo(0) String @Foo(1)[] @Foo(2)[] @Foo(3)[] field;
public boolean process(Set<? extends TypeElement> tes, RoundEnvironment renv) {

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2014, 2016, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2014, 2017, 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
@ -23,7 +23,7 @@
/*
* @test
* @bug 4981566 5028634 5094412 6304984 7025786 7025789 8001112 8028545 8000961 8030610
* @bug 4981566 5028634 5094412 6304984 7025786 7025789 8001112 8028545 8000961 8030610 8028546
* @summary Check interpretation of -target and -source options
* @modules java.compiler
* jdk.compiler
@ -69,6 +69,7 @@ public class Versions {
check("53.0", "-source 1.7");
check("53.0", "-source 1.8");
check("53.0", "-source 1.9");
check("53.0", "-source 1.10");
check_source_target("50.0", "6", "6");
check_source_target("51.0", "6", "7");
@ -80,6 +81,7 @@ public class Versions {
check_source_target("53.0", "7", "9");
check_source_target("53.0", "8", "9");
check_source_target("53.0", "9", "9");
check_source_target("53.0", "10", "10");
checksrc16("-source 1.6");
checksrc16("-source 6");
@ -93,19 +95,26 @@ public class Versions {
checksrc18("-source 8");
checksrc18("-source 1.8", "-target 1.8");
checksrc18("-source 8", "-target 8");
checksrc19();
checksrc19("-source 1.9");
checksrc19("-source 9");
checksrc19("-source 1.9", "-target 1.9");
checksrc19("-source 9", "-target 9");
checksrc19("-target 1.9");
checksrc19("-target 9");
checksrc110();
checksrc110("-source 1.10");
checksrc110("-source 10");
checksrc110("-source 1.10", "-target 1.10");
checksrc110("-source 10", "-target 10");
checksrc110("-target 1.10");
checksrc110("-target 10");
fail("-source 7", "-target 1.6", "Base.java");
fail("-source 8", "-target 1.6", "Base.java");
fail("-source 8", "-target 1.7", "Base.java");
fail("-source 9", "-target 1.7", "Base.java");
fail("-source 9", "-target 1.8", "Base.java");
fail("-source 10", "-target 1.7", "Base.java");
fail("-source 10", "-target 1.8", "Base.java");
fail("-source 1.5", "-target 1.5", "Base.java");
fail("-source 1.4", "-target 1.4", "Base.java");
@ -202,6 +211,11 @@ public class Versions {
checksrc18(args);
}
protected void checksrc110(String... args) {
printargs("checksrc110", args);
checksrc19(args);
}
protected void pass(String... args) {
printargs("pass", args);

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2016, 2017, 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
@ -49,6 +49,7 @@ public class TestRelease {
assertTrue(invoke("7"));
assertTrue(invoke("8"));
assertTrue(invoke("9"));
assertTrue(invoke("10"));
}
@Test

View File

@ -69,7 +69,7 @@ $(eval $(call SetupJavaCompiler,GENERATE_OLDBYTECODE, \
$(eval $(call SetupJavaCompiler,GENERATE_JDKBYTECODE, \
JVM := $(JAVA_JAVAC), \
JAVAC := $(NEW_JAVAC), \
FLAGS := -source 9 -target 9 \
FLAGS := -source 10 -target 10 \
-encoding ascii -XDignore.symbol.file=true $(JAVAC_WARNINGS), \
SERVER_DIR := $(SJAVAC_SERVER_DIR), \
SERVER_JVM := $(SJAVAC_SERVER_JAVA)))
@ -79,7 +79,7 @@ $(eval $(call SetupJavaCompiler,GENERATE_JDKBYTECODE, \
$(eval $(call SetupJavaCompiler,GENERATE_JDKBYTECODE_NOWARNINGS, \
JVM := $(JAVA_JAVAC), \
JAVAC := $(NEW_JAVAC), \
FLAGS := -source 9 -target 9 \
FLAGS := -source 10 -target 10 \
-encoding ascii -XDignore.symbol.file=true $(DISABLE_WARNINGS), \
SERVER_DIR := $(SJAVAC_SERVER_DIR), \
SERVER_JVM := $(SJAVAC_SERVER_JAVA)))

View File

@ -387,5 +387,7 @@ ace1d994bca775d6545a4c874ae73d1dfc9ec18b jdk-9+150
2a0437036a64853334e538044eb68d2df70075fa jdk-9+151
ddc52e72757086a75a54371e8e7f56a3f89f1e55 jdk-9+152
19aaaf2d02b7d6986538cd9a8c46901ecb50eebf jdk-9+153
a84b49cfee63716975535abae2865ffef4dd6474 jdk-10+0
a84b49cfee63716975535abae2865ffef4dd6474 jdk-9+154
f9bb37a817b3cd3b758a60f3c68258a6554eb382 jdk-9+155
d577398d31111be4bdaa08008247cf4242eaea94 jdk-9+156

View File

@ -1 +1 @@
project=jdk9
project=jdk10