--- a/.hgtags-top-repo Thu Feb 09 18:13:36 2017 +0000
+++ b/.hgtags-top-repo Wed Jul 05 22:49:24 2017 +0200
@@ -396,5 +396,7 @@
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
--- a/.jcheck/conf Thu Feb 09 18:13:36 2017 +0000
+++ b/.jcheck/conf Wed Jul 05 22:49:24 2017 +0200
@@ -1,1 +1,1 @@
-project=jdk9
+project=jdk10
--- a/common/autoconf/version-numbers Thu Feb 09 18:13:36 2017 +0000
+++ b/common/autoconf/version-numbers Wed Jul 05 22:49:24 2017 +0200
@@ -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
--- a/common/conf/jib-profiles.js Thu Feb 09 18:13:36 2017 +0000
+++ b/common/conf/jib-profiles.js Wed Jul 05 22:49:24 2017 +0200
@@ -1080,7 +1080,7 @@
+ "." + (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;
--- a/hotspot/.hgtags Thu Feb 09 18:13:36 2017 +0000
+++ b/hotspot/.hgtags Wed Jul 05 22:49:24 2017 +0200
@@ -556,5 +556,7 @@
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
--- a/hotspot/.jcheck/conf Thu Feb 09 18:13:36 2017 +0000
+++ b/hotspot/.jcheck/conf Wed Jul 05 22:49:24 2017 +0200
@@ -1,1 +1,1 @@
-project=jdk9
+project=jdk10
--- a/hotspot/src/cpu/aarch64/vm/c1_globals_aarch64.hpp Thu Feb 09 18:13:36 2017 +0000
+++ b/hotspot/src/cpu/aarch64/vm/c1_globals_aarch64.hpp Wed Jul 05 22:49:24 2017 +0200
@@ -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 @@
// 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, CSEArrayLength, false);
define_pd_global(bool, TwoOperandLIRForm, false );
-define_pd_global(intx, SafepointPollOffset, 0 );
-
#endif // CPU_AARCH64_VM_C1_GLOBALS_AARCH64_HPP
--- a/hotspot/src/cpu/aarch64/vm/c2_globals_aarch64.hpp Thu Feb 09 18:13:36 2017 +0000
+++ b/hotspot/src/cpu/aarch64/vm/c2_globals_aarch64.hpp Wed Jul 05 22:49:24 2017 +0200
@@ -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, 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);
--- a/hotspot/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/tools/HeapSummary.java Thu Feb 09 18:13:36 2017 +0000
+++ b/hotspot/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/tools/HeapSummary.java Wed Jul 05 22:49:24 2017 +0200
@@ -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 @@
// 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.");
}
--- a/hotspot/src/os/solaris/vm/os_solaris.cpp Thu Feb 09 18:13:36 2017 +0000
+++ b/hotspot/src/os/solaris/vm/os_solaris.cpp Wed Jul 05 22:49:24 2017 +0200
@@ -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 @@
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
--- a/hotspot/src/share/vm/gc/cms/concurrentMarkSweepGeneration.cpp Thu Feb 09 18:13:36 2017 +0000
+++ b/hotspot/src/share/vm/gc/cms/concurrentMarkSweepGeneration.cpp Wed Jul 05 22:49:24 2017 +0200
@@ -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 @@
_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 @@
// 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 @@
// 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();
--- a/hotspot/src/share/vm/oops/method.cpp Thu Feb 09 18:13:36 2017 +0000
+++ b/hotspot/src/share/vm/oops/method.cpp Wed Jul 05 22:49:24 2017 +0200
@@ -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 @@
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()));
--- a/hotspot/src/share/vm/prims/jvm.cpp Thu Feb 09 18:13:36 2017 +0000
+++ b/hotspot/src/share/vm/prims/jvm.cpp Wed Jul 05 22:49:24 2017 +0200
@@ -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 @@
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 @@
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);
--- a/hotspot/src/share/vm/runtime/arguments.cpp Thu Feb 09 18:13:36 2017 +0000
+++ b/hotspot/src/share/vm/runtime/arguments.cpp Wed Jul 05 22:49:24 2017 +0200
@@ -375,53 +375,17 @@
// -------------- 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 @@
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 @@
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_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 @@
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_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 @@
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 @@
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 @@
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 @@
}
}
- 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;
}
--- a/hotspot/src/share/vm/runtime/arguments.hpp Thu Feb 09 18:13:36 2017 +0000
+++ b/hotspot/src/share/vm/runtime/arguments.hpp Wed Jul 05 22:49:24 2017 +0200
@@ -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 @@
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();
--- a/hotspot/src/share/vm/runtime/globals.hpp Thu Feb 09 18:13:36 2017 +0000
+++ b/hotspot/src/share/vm/runtime/globals.hpp Wed Jul 05 22:49:24 2017 +0200
@@ -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 @@
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 @@
"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 @@
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 @@
"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 @@
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") \
\
--- a/hotspot/test/TEST.groups Thu Feb 09 18:13:36 2017 +0000
+++ b/hotspot/test/TEST.groups Wed Jul 05 22:49:24 2017 +0200
@@ -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 @@
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
--- a/hotspot/test/gc/arguments/TestExplicitGCInvokesConcurrentAndUnloadsClasses.java Thu Feb 09 18:13:36 2017 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -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);
- }
-}
--- a/hotspot/test/gc/arguments/TestSelectDefaultGC.java Thu Feb 09 18:13:36 2017 +0000
+++ b/hotspot/test/gc/arguments/TestSelectDefaultGC.java Wed Jul 05 22:49:24 2017 +0200
@@ -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 @@
assertVMOption(output, "UseSerialGC", !isServer);
// CMS is never default
assertVMOption(output, "UseConcMarkSweepGC", false);
- assertVMOption(output, "UseParNewGC", false);
}
public static void main(String[] args) throws Exception {
--- a/hotspot/test/gc/startup_warnings/TestDefNewCMS.java Thu Feb 09 18:13:36 2017 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,47 +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 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
-*/
-
-import jdk.test.lib.process.ProcessTools;
-import jdk.test.lib.process.OutputAnalyzer;
-
-public class TestDefNewCMS {
-
- 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);
- }
-
-}
--- a/hotspot/test/gc/startup_warnings/TestParNewCMS.java Thu Feb 09 18:13:36 2017 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -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 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
-*/
-
-import jdk.test.lib.process.ProcessTools;
-import jdk.test.lib.process.OutputAnalyzer;
-
-
-public class TestParNewCMS {
-
- 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);
- }
-
-}
--- a/hotspot/test/gc/startup_warnings/TestParNewSerialOld.java Thu Feb 09 18:13:36 2017 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -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);
- }
-
-}
--- a/hotspot/test/gc/startup_warnings/TestUseAutoGCSelectPolicy.java Thu Feb 09 18:13:36 2017 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -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);
- }
-}
--- a/hotspot/test/runtime/CommandLine/ObsoleteFlagErrorMessage.java Thu Feb 09 18:13:36 2017 +0000
+++ b/hotspot/test/runtime/CommandLine/ObsoleteFlagErrorMessage.java Wed Jul 05 22:49:24 2017 +0200
@@ -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 @@
// 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");
}
}
--- a/hotspot/test/runtime/CommandLine/VMAliasOptions.java Thu Feb 09 18:13:36 2017 +0000
+++ b/hotspot/test/runtime/CommandLine/VMAliasOptions.java Wed Jul 05 22:49:24 2017 +0200
@@ -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 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" },
};
--- a/hotspot/test/runtime/CommandLine/VMDeprecatedOptions.java Thu Feb 09 18:13:36 2017 +0000
+++ b/hotspot/test/runtime/CommandLine/VMDeprecatedOptions.java Wed Jul 05 22:49:24 2017 +0200
@@ -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 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"}
};
--- a/hotspot/test/runtime/NMT/AutoshutdownNMT.java Thu Feb 09 18:13:36 2017 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,47 +0,0 @@
-/*
- * Copyright (c) 2014, 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
- * @key nmt
- * @summary Test for deprecated message if -XX:-AutoShutdownNMT is specified
- * @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 AutoshutdownNMT {
-
- 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");
- }
-}
--- a/jdk/.hgtags Thu Feb 09 18:13:36 2017 +0000
+++ b/jdk/.hgtags Wed Jul 05 22:49:24 2017 +0200
@@ -396,5 +396,7 @@
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
--- a/jdk/.jcheck/conf Thu Feb 09 18:13:36 2017 +0000
+++ b/jdk/.jcheck/conf Wed Jul 05 22:49:24 2017 +0200
@@ -1,1 +1,1 @@
-project=jdk9
+project=jdk10
--- a/jdk/make/launcher/Launcher-java.base.gmk Thu Feb 09 18:13:36 2017 +0000
+++ b/jdk/make/launcher/Launcher-java.base.gmk Wed Jul 05 22:49:24 2017 +0200
@@ -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
@@ -135,38 +135,17 @@
################################################################################
-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
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/src/java.base/aix/classes/sun/nio/ch/DefaultAsynchronousChannelProvider.java Wed Jul 05 22:49:24 2017 +0200
@@ -0,0 +1,47 @@
+/*
+ * 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. 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.
+ */
+
+package sun.nio.ch;
+
+import java.nio.channels.spi.AsynchronousChannelProvider;
+
+/**
+ * Creates this platform's default AsynchronousChannelProvider
+ */
+
+public class DefaultAsynchronousChannelProvider {
+
+ /**
+ * Prevent instantiation.
+ */
+ private DefaultAsynchronousChannelProvider() { }
+
+ /**
+ * Returns the default AsynchronousChannelProvider.
+ */
+ public static AsynchronousChannelProvider create() {
+ return new AixAsynchronousChannelProvider();
+ }
+}
--- a/jdk/src/java.base/aix/classes/sun/nio/ch/DefaultSelectorProvider.java Thu Feb 09 18:13:36 2017 +0000
+++ b/jdk/src/java.base/aix/classes/sun/nio/ch/DefaultSelectorProvider.java Wed Jul 05 22:49:24 2017 +0200
@@ -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 @@
* Returns the default SelectorProvider.
*/
public static SelectorProvider create() {
- return new sun.nio.ch.PollSelectorProvider();
+ return new PollSelectorProvider();
}
-
}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/src/java.base/linux/classes/sun/nio/ch/DefaultAsynchronousChannelProvider.java Wed Jul 05 22:49:24 2017 +0200
@@ -0,0 +1,47 @@
+/*
+ * 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. 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.
+ */
+
+package sun.nio.ch;
+
+import java.nio.channels.spi.AsynchronousChannelProvider;
+
+/**
+ * Creates this platform's default AsynchronousChannelProvider
+ */
+
+public class DefaultAsynchronousChannelProvider {
+
+ /**
+ * Prevent instantiation.
+ */
+ private DefaultAsynchronousChannelProvider() { }
+
+ /**
+ * Returns the default AsynchronousChannelProvider.
+ */
+ public static AsynchronousChannelProvider create() {
+ return new LinuxAsynchronousChannelProvider();
+ }
+}
--- a/jdk/src/java.base/linux/classes/sun/nio/ch/DefaultSelectorProvider.java Thu Feb 09 18:13:36 2017 +0000
+++ b/jdk/src/java.base/linux/classes/sun/nio/ch/DefaultSelectorProvider.java Wed Jul 05 22:49:24 2017 +0200
@@ -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 @@
* Returns the default SelectorProvider.
*/
public static SelectorProvider create() {
- return new sun.nio.ch.EPollSelectorProvider();
+ return new EPollSelectorProvider();
}
-
}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/src/java.base/macosx/classes/sun/nio/ch/DefaultAsynchronousChannelProvider.java Wed Jul 05 22:49:24 2017 +0200
@@ -0,0 +1,47 @@
+/*
+ * 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. 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.
+ */
+
+package sun.nio.ch;
+
+import java.nio.channels.spi.AsynchronousChannelProvider;
+
+/**
+ * Creates this platform's default AsynchronousChannelProvider
+ */
+
+public class DefaultAsynchronousChannelProvider {
+
+ /**
+ * Prevent instantiation.
+ */
+ private DefaultAsynchronousChannelProvider() { }
+
+ /**
+ * Returns the default AsynchronousChannelProvider.
+ */
+ public static AsynchronousChannelProvider create() {
+ return new BsdAsynchronousChannelProvider();
+ }
+}
--- a/jdk/src/java.base/macosx/classes/sun/nio/ch/DefaultSelectorProvider.java Thu Feb 09 18:13:36 2017 +0000
+++ b/jdk/src/java.base/macosx/classes/sun/nio/ch/DefaultSelectorProvider.java Wed Jul 05 22:49:24 2017 +0200
@@ -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 @@
* Returns the default SelectorProvider.
*/
public static SelectorProvider create() {
- return new sun.nio.ch.KQueueSelectorProvider();
+ return new KQueueSelectorProvider();
}
-
}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/src/java.base/solaris/classes/sun/nio/ch/DefaultAsynchronousChannelProvider.java Wed Jul 05 22:49:24 2017 +0200
@@ -0,0 +1,47 @@
+/*
+ * 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. 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.
+ */
+
+package sun.nio.ch;
+
+import java.nio.channels.spi.AsynchronousChannelProvider;
+
+/**
+ * Creates this platform's default AsynchronousChannelProvider
+ */
+
+public class DefaultAsynchronousChannelProvider {
+
+ /**
+ * Prevent instantiation.
+ */
+ private DefaultAsynchronousChannelProvider() { }
+
+ /**
+ * Returns the default AsynchronousChannelProvider.
+ */
+ public static AsynchronousChannelProvider create() {
+ return new SolarisAsynchronousChannelProvider();
+ }
+}
--- a/jdk/src/java.base/solaris/classes/sun/nio/ch/DefaultSelectorProvider.java Thu Feb 09 18:13:36 2017 +0000
+++ b/jdk/src/java.base/solaris/classes/sun/nio/ch/DefaultSelectorProvider.java Wed Jul 05 22:49:24 2017 +0200
@@ -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 @@
* Returns the default SelectorProvider.
*/
public static SelectorProvider create() {
- return new sun.nio.ch.DevPollSelectorProvider();
+ return new DevPollSelectorProvider();
}
-
}
--- a/jdk/src/java.base/unix/classes/sun/nio/ch/DefaultAsynchronousChannelProvider.java Thu Feb 09 18:13:36 2017 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,75 +0,0 @@
-/*
- * Copyright (c) 2008, 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.
- */
-
-package sun.nio.ch;
-
-import java.nio.channels.spi.AsynchronousChannelProvider;
-import sun.security.action.GetPropertyAction;
-
-/**
- * Creates this platform's default asynchronous channel provider
- */
-
-public class DefaultAsynchronousChannelProvider {
-
- /**
- * Prevent instantiation.
- */
- 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");
- }
-}
--- a/jdk/src/java.base/unix/native/libnet/Inet4AddressImpl.c Thu Feb 09 18:13:36 2017 +0000
+++ b/jdk/src/java.base/unix/native/libnet/Inet4AddressImpl.c Wed Jul 05 22:49:24 2017 +0200
@@ -46,7 +46,13 @@
#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 @@
*/
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 @@
}
/*
- * 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 @@
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);
}
-
- freeaddrinfo(res);
-
+ if (res != NULL) {
+ freeaddrinfo(res);
+ }
return ret;
}
@@ -244,164 +215,243 @@
* 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];
+ jbyte caddr[4];
+ jint addr;
+ struct sockaddr_in sa;
- char host[NI_MAXHOST+1];
- int error = 0;
- int len = 0;
- jbyte caddr[4];
-
- struct sockaddr_in him4;
- struct sockaddr *sa;
-
- jint addr;
+ // 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;
- }
+ // 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");
+ }
+#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);
- 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;
+ 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;
+ }
+ }
}
-
- if (him->sin_addr.s_addr == 0) {
- close(fd);
- return JNI_TRUE;
- }
- }
-
- }
- } while (tmout2 > 0);
- timeout -= 1000;
- } while (timeout >0);
+ } while (tmout2 > 0);
+ timeout -= 1000;
+ } while (timeout > 0);
close(fd);
return JNI_FALSE;
}
@@ -413,149 +463,51 @@
*/
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.
- */
- 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 *)&sa, 0, sizeof(SOCKETADDRESS));
+ sa.sa4.sin_addr.s_addr = htonl(addr);
+ sa.sa4.sin_family = AF_INET;
- /*
- * 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));
+ // 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);
+ memset((char *)&inf, 0, sizeof(SOCKETADDRESS));
+ inf.sa4.sin_addr.s_addr = htonl(addr);
+ inf.sa4.sin_family = AF_INET;
+ netif = &inf;
}
- /*
- * 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;
+ // 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) {
+ 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);
}
}
--- a/jdk/src/java.base/unix/native/libnet/Inet6AddressImpl.c Thu Feb 09 18:13:36 2017 +0000
+++ b/jdk/src/java.base/unix/native/libnet/Inet6AddressImpl.c Wed Jul 05 22:49:24 2017 +0200
@@ -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 @@
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 @@
} 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 @@
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 @@
#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 @@
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 @@
}
}
if (t < 16) {
- itr = itr->ai_next;
+ iteratorNew = iteratorNew->ai_next;
continue;
} else {
skip = 1;
@@ -346,16 +303,16 @@
}
} 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 @@
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 @@
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 @@
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 @@
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);
}
-
- freeaddrinfo(res);
-
+ if (res != NULL) {
+ freeaddrinfo(res);
+ }
return ret;
}
@@ -465,171 +410,252 @@
* 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);
+ setsockopt(fd, SOL_SOCKET, SO_RCVBUF, &size, sizeof(size));
- /* 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;
- }
+ if (bind(fd, &netif->sa, sizeof(struct sockaddr_in6)) <0) {
+ NET_ThrowNew(env, errno, "Can't bind socket");
+ close(fd);
+ return JNI_FALSE;
+ }
}
+
+ // 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 {
- 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;
- }
+ // 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);
- 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;
+ 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;
+ }
+ }
}
- if (NET_IsZeroAddr(caddr)) {
- close(fd);
- return JNI_TRUE;
- }
- }
- }
- } while (tmout2 > 0);
- timeout -= 1000;
+ } while (tmout2 > 0);
+ timeout -= 1000;
} while (timeout > 0);
close(fd);
return JNI_FALSE;
@@ -642,157 +668,61 @@
*/
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;
- }
- /*
- * 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 JNI_FALSE;
}
- memset((void *) caddr, 0, 16);
- memset((void *) &him6, 0, sizeof(him6));
- (*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);
+ // 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);
}
- /* 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));
+ // load address to SOCKETADDRESS
+ memset((char *)caddr, 0, 16);
+ (*env)->GetByteArrayRegion(env, addrArray, 0, 16, caddr);
+ 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 {
+ sa.sa6.sin6_scope_id = getDefaultIPv6Interface(&sa.sa6.sin6_addr);
+#endif
}
- /*
- * 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;
- }
+ // 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;
}
- 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;
- } 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;
+ // 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);
}
}
--- a/jdk/src/java.base/windows/native/libnet/Inet4AddressImpl.c Thu Feb 09 18:13:36 2017 +0000
+++ b/jdk/src/java.base/windows/native/libnet/Inet4AddressImpl.c Wed Jul 05 22:49:24 2017 +0200
@@ -30,60 +30,6 @@
#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 @@
* 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 @@
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 @@
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 @@
error = getaddrinfo(hostname, NULL, &hints, &res);
if (error) {
+ // report error
NET_ThrowByNameWithLastError(env, "java/net/UnknownHostException",
hostname);
goto cleanupAndReturn;
@@ -311,145 +206,86 @@
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;
+ int connect_rv = -1;
WSAEVENT hEvent;
- int connect_rv = -1;
- int sz;
- /**
- * 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 */
- 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;
+ }
+
+ 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 (WSAGetLastError() != WSAEWOULDBLOCK) {
- NET_ThrowByNameWithLastError(env, JNU_JAVANETPKG "ConnectException",
- "connect failed");
+ if (connect_rv == 0 || connect_rv == WSAECONNREFUSED) {
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 @@
* 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 @@
// 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 @@
// 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 @@
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 @@
// 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 @@
*/
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));
+
+ // convert IP address from byte array to integer
+ 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);
+ 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 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);
}
}
-
--- a/jdk/src/java.base/windows/native/libnet/Inet6AddressImpl.c Thu Feb 09 18:13:36 2017 +0000
+++ b/jdk/src/java.base/windows/native/libnet/Inet6AddressImpl.c Wed Jul 05 22:49:24 2017 +0200
@@ -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 @@
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 @@
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 @@
}
}
if (t < 16) {
- itr = itr->ai_next;
+ iteratorNew = iteratorNew->ai_next;
continue;
} else {
skip = 1;
@@ -136,16 +128,16 @@
}
} 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 @@
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);
}
-
- freeaddrinfo(res);
-
+ if (res != NULL) {
+ freeaddrinfo(res);
+ }
return ret;
}
@@ -249,57 +235,48 @@
* 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 @@
* 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;
+ int connect_rv = -1;
WSAEVENT hEvent;
- int connect_rv = -1;
+ // 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;
- }
+ }
- 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);
+ 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 (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 @@
* 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 @@
}
//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 @@
free(ReplyBuffer);
IcmpCloseHandle(hIcmpFile);
-
- if (dwRetVal != 0) {
+ if (dwRetVal == 0) { // if the call failed
+ return JNI_FALSE;
+ } else {
return JNI_TRUE;
- } else {
- return JNI_FALSE;
}
}
@@ -474,75 +433,64 @@
*/
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;
- }
- len = sizeof(struct sockaddr_in6);
-
- /**
- * A network interface was specified, let's convert the address
- */
- 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;
+ sa.sa6.sin6_scope_id = scope;
}
+ // 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;
+ }
+
+ // 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;
}
--- a/jdk/test/ProblemList.txt Thu Feb 09 18:13:36 2017 +0000
+++ b/jdk/test/ProblemList.txt Wed Jul 05 22:49:24 2017 +0200
@@ -261,6 +261,11 @@
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
--- a/jdk/test/com/sun/management/HotSpotDiagnosticMXBean/CheckOrigin.java Thu Feb 09 18:13:36 2017 +0000
+++ b/jdk/test/com/sun/management/HotSpotDiagnosticMXBean/CheckOrigin.java Wed Jul 05 22:49:24 2017 +0200
@@ -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 @@
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 @@
// 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);
}
--- a/jdk/test/java/lang/management/MemoryMXBean/LowMemoryTest.java Thu Feb 09 18:13:36 2017 +0000
+++ b/jdk/test/java/lang/management/MemoryMXBean/LowMemoryTest.java Wed Jul 05 22:49:24 2017 +0200
@@ -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"
*/
--- a/jdk/test/java/lang/management/MemoryMXBean/LowMemoryTest2.sh Thu Feb 09 18:13:36 2017 +0000
+++ b/jdk/test/java/lang/management/MemoryMXBean/LowMemoryTest2.sh Wed Jul 05 22:49:24 2017 +0200
@@ -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 @@
# 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.
--- a/jdk/test/java/lang/management/MemoryMXBean/ResetPeakMemoryUsage.java Thu Feb 09 18:13:36 2017 +0000
+++ b/jdk/test/java/lang/management/MemoryMXBean/ResetPeakMemoryUsage.java Wed Jul 05 22:49:24 2017 +0200
@@ -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"
*/
--- a/jdk/test/java/lang/module/MultiReleaseJarTest.java Thu Feb 09 18:13:36 2017 +0000
+++ b/jdk/test/java/lang/module/MultiReleaseJarTest.java Wed Jul 05 22:49:24 2017 +0200
@@ -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
@@ -65,7 +65,7 @@
private static final String MODULE_INFO = "module-info.class";
- private static final int RELEASE = Runtime.version().major();
+ private static final String RELEASE = "" + Runtime.version().major();
// are multi-release JARs enabled?
private static final boolean MULTI_RELEASE;
@@ -88,8 +88,8 @@
.moduleInfo("module-info.class", descriptor)
.resource("p/Main.class")
.resource("p/Helper.class")
- .resource("META-INF/versions/9/p/Helper.class")
- .resource("META-INF/versions/9/p/internal/Helper9.class")
+ .resource("META-INF/versions/" + RELEASE + "/p/Helper.class")
+ .resource("META-INF/versions/" + RELEASE + "/p/internal/HelperNew.class")
.build();
// find the module
@@ -131,9 +131,9 @@
.moduleInfo(MODULE_INFO, descriptor1)
.resource("p/Main.class")
.resource("p/Helper.class")
- .moduleInfo("META-INF/versions/9/" + MODULE_INFO, descriptor2)
- .resource("META-INF/versions/9/p/Helper.class")
- .resource("META-INF/versions/9/p/internal/Helper9.class")
+ .moduleInfo("META-INF/versions/" + RELEASE + "/" + MODULE_INFO, descriptor2)
+ .resource("META-INF/versions/" + RELEASE + "/p/Helper.class")
+ .resource("META-INF/versions/" + RELEASE + "/p/internal/HelperNew.class")
.build();
// find the module
@@ -161,8 +161,8 @@
Path jar = new JarBuilder(name)
.resource("p/Main.class")
.resource("p/Helper.class")
- .resource("META-INF/versions/9/p/Helper.class")
- .resource("META-INF/versions/9/p/internal/Helper9.class")
+ .resource("META-INF/versions/" + RELEASE + "/p/Helper.class")
+ .resource("META-INF/versions/" + RELEASE + "/p/internal/HelperNew.class")
.build();
// find the module
@@ -200,7 +200,7 @@
Path jar = new JarBuilder(name)
.moduleInfo(MODULE_INFO, descriptor1)
- .moduleInfo("META-INF/versions/9/" + MODULE_INFO, descriptor2)
+ .moduleInfo("META-INF/versions/" + RELEASE + "/" + MODULE_INFO, descriptor2)
.build();
// find the module
--- a/jdk/test/java/security/Provider/ProviderVersionCheck.java Thu Feb 09 18:13:36 2017 +0000
+++ b/jdk/test/java/security/Provider/ProviderVersionCheck.java Wed Jul 05 22:49:24 2017 +0200
@@ -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 @@
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;
--- a/jdk/test/sun/security/tools/jarsigner/multiRelease/MVJarSigningTest.java Thu Feb 09 18:13:36 2017 +0000
+++ b/jdk/test/sun/security/tools/jarsigner/multiRelease/MVJarSigningTest.java Wed Jul 05 22:49:24 2017 +0200
@@ -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 @@
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
--- a/make/common/SetupJavaCompilers.gmk Thu Feb 09 18:13:36 2017 +0000
+++ b/make/common/SetupJavaCompilers.gmk Wed Jul 05 22:49:24 2017 +0200
@@ -69,7 +69,7 @@
$(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_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)))