Hi,

On 07/01/2016 10:36 AM, Paul Sandoz wrote:
On 1 Jul 2016, at 00:53, Doug Lea <d...@cs.oswego.edu> wrote:

On 06/30/2016 10:08 AM, Paul Sandoz wrote:
Hi Peter,

Thanks, that’s interesting. I am uncertain if our 166 fellows will be
reluctant or not to pull in a dependency on jdk.internal.misc.SharedSecrets.

Background: we are reluctant to rely on anything that makes sources impossible
to use in (usually, upcoming versions of) Android. Which probably
doesn't directly apply here.

But my main concern in this case is that we need better assurance
that there are no possible start-up circularities, since we've already
had some near-miss experiences with ThreadLocalRandom. Is there a
solid argument?

ThreadLocalRandom was tricky, yes!

But I think this one is pretty safe:

http://cr.openjdk.java.net/~plevart/misc/JavaLangThreadAccess/webrev.Striped64/

What it does in Thread.<clinit> is instantiate an anonymous class implementing JavaLangThreadAccess interface and injecting the instance into the SharedSecrets class' static field. This triggers initializing just 3 classes:

- JavaLangThreadAccess interface
- Thread$NN anonymous class implementing JavaLangThreadAccess
- SharedSecrets class

That's all. The patch modifies SharedSecrets so that it doesn't initialize anything else (originally it initialized the Unsafe class which was premature and the JVM bootstrap failed because of that).

This is the diff between the traces of loading classes on unpatched JDK 9 (jsr166 jdk9 integration wave 7 not applied yet) and with above patch applied when running an empty program:

[peter@peterl tmp]$ diff -c cltrace0.txt cltrace1.txt
*** cltrace0.txt        2016-07-07 17:04:21.872277904 +0200
--- cltrace1.txt        2016-07-07 17:04:26.368307983 +0200
***************
*** 1,4 ****
! [info][class,load] opened: /home/peter/Apps64/jdk1.9.0.default/lib/modules
  [info][class,load] java.lang.Object source: jrt:/java.base
  [info][class,load] java.io.Serializable source: jrt:/java.base
  [info][class,load] java.lang.Comparable source: jrt:/java.base
--- 1,4 ----
! [info][class,load] opened: /home/peter/work/hg/jdk9-dev/build/linux-x86_64-normal-server-release/images/jdk/lib/modules
  [info][class,load] java.lang.Object source: jrt:/java.base
  [info][class,load] java.io.Serializable source: jrt:/java.base
  [info][class,load] java.lang.Comparable source: jrt:/java.base
***************
*** 123,128 ****
--- 123,131 ----
  [info][class,load] java.security.BasicPermission source: jrt:/java.base
  [info][class,load] java.lang.RuntimePermission source: jrt:/java.base
  [info][class,load] java.lang.StringLatin1 source: jrt:/java.base
+ [info][class,load] jdk.internal.misc.JavaLangThreadAccess source: jrt:/java.base
+ [info][class,load] java.lang.Thread$2 source: jrt:/java.base
+ [info][class,load] jdk.internal.misc.SharedSecrets source: jrt:/java.base
  [info][class,load] java.security.AccessController source: jrt:/java.base
  [info][class,load] java.util.Collections source: jrt:/java.base
  [info][class,load] java.lang.Iterable source: jrt:/java.base
***************
*** 167,173 ****
[info][class,load] java.lang.ref.ReferenceQueue$Lock source: jrt:/java.base [info][class,load] jdk.internal.misc.JavaLangRefAccess source: jrt:/java.base
  [info][class,load] java.lang.ref.Reference$1 source: jrt:/java.base
- [info][class,load] jdk.internal.misc.SharedSecrets source: jrt:/java.base
  [info][class,load] java.lang.Class$Atomic source: jrt:/java.base
[info][class,load] java.lang.reflect.ReflectPermission source: jrt:/java.base [info][class,load] jdk.internal.reflect.ReflectionFactory$GetReflectionFactoryAction source: jrt:/java.base
--- 170,175 ----
***************
*** 389,413 ****
[info][class,load] jdk.internal.module.SystemModules source: jrt:/java.base [info][class,load] java.lang.module.ModuleDescriptor source: jrt:/java.base
  [info][class,load] jdk.internal.module.Builder source: jrt:/java.base
[info][class,load] jdk.internal.misc.JavaLangModuleAccess source: jrt:/java.base [info][class,load] java.lang.module.ModuleDescriptor$1 source: jrt:/java.base [info][class,load] java.lang.module.ModuleDescriptor$Requires$Modifier source: jrt:/java.base [info][class,load] java.lang.module.ModuleDescriptor$Requires source: jrt:/java.base - [info][class,load] java.util.Collections$EmptyIterator source: jrt:/java.base
  [info][class,load] java.util.Collections$1 source: jrt:/java.base
[info][class,load] java.lang.module.ModuleDescriptor$Exports source: jrt:/java.base
  [info][class,load] java.util.HashMap$TreeNode source: jrt:/java.base
[info][class,load] java.lang.module.ModuleDescriptor$Version source: jrt:/java.base
  [info][class,load] java.util.ArrayList source: jrt:/java.base
- [info][class,load] java.util.Collections$UnmodifiableCollection source: jrt:/java.base - [info][class,load] java.util.Collections$UnmodifiableSet source: jrt:/java.base [info][class,load] java.util.Collections$UnmodifiableMap source: jrt:/java.base - [info][class,load] java.lang.module.ModuleDescriptor$Provides source: jrt:/java.base
  [info][class,load] java.util.HashMap$KeySet source: jrt:/java.base
  [info][class,load] java.util.HashMap$HashIterator source: jrt:/java.base
  [info][class,load] java.util.HashMap$KeyIterator source: jrt:/java.base
- [info][class,load] jdk.internal.module.ModuleHashes source: jrt:/java.base
  [info][class,load] java.util.LinkedHashSet source: jrt:/java.base
[info][class,load] jdk.internal.module.ModuleHashes$HashSupplier source: jrt:/java.base [info][class,load] java.lang.module.SystemModuleFinder$2 source: jrt:/java.base
  [info][class,load] java.util.function.Supplier source: jrt:/java.base
--- 391,416 ----
[info][class,load] jdk.internal.module.SystemModules source: jrt:/java.base [info][class,load] java.lang.module.ModuleDescriptor source: jrt:/java.base
  [info][class,load] jdk.internal.module.Builder source: jrt:/java.base
+ [info][class,load] jdk.internal.misc.SharedSecrets$U source: jrt:/java.base [info][class,load] jdk.internal.misc.JavaLangModuleAccess source: jrt:/java.base [info][class,load] java.lang.module.ModuleDescriptor$1 source: jrt:/java.base [info][class,load] java.lang.module.ModuleDescriptor$Requires$Modifier source: jrt:/java.base [info][class,load] java.lang.module.ModuleDescriptor$Requires source: jrt:/java.base
  [info][class,load] java.util.Collections$1 source: jrt:/java.base
+ [info][class,load] java.util.Collections$EmptyIterator source: jrt:/java.base [info][class,load] java.lang.module.ModuleDescriptor$Exports source: jrt:/java.base + [info][class,load] java.util.Collections$UnmodifiableCollection source: jrt:/java.base + [info][class,load] java.util.Collections$UnmodifiableSet source: jrt:/java.base
  [info][class,load] java.util.HashMap$TreeNode source: jrt:/java.base
+ [info][class,load] java.lang.module.ModuleDescriptor$Provides source: jrt:/java.base [info][class,load] java.lang.module.ModuleDescriptor$Version source: jrt:/java.base
  [info][class,load] java.util.ArrayList source: jrt:/java.base
[info][class,load] java.util.Collections$UnmodifiableMap source: jrt:/java.base
  [info][class,load] java.util.HashMap$KeySet source: jrt:/java.base
  [info][class,load] java.util.HashMap$HashIterator source: jrt:/java.base
  [info][class,load] java.util.HashMap$KeyIterator source: jrt:/java.base
  [info][class,load] java.util.LinkedHashSet source: jrt:/java.base
+ [info][class,load] jdk.internal.module.ModuleHashes source: jrt:/java.base
[info][class,load] jdk.internal.module.ModuleHashes$HashSupplier source: jrt:/java.base [info][class,load] java.lang.module.SystemModuleFinder$2 source: jrt:/java.base
  [info][class,load] java.util.function.Supplier source: jrt:/java.base


...what we see is that the patch actually delays loading of some classes (except the 3 classes mentioned).

Regards, Peter


I suggest we spin this off from the main issue and investigate afterwards, i 
have logged an issue:

   https://bugs.openjdk.java.net/browse/JDK-8160710 
<https://bugs.openjdk.java.net/browse/JDK-8160710>

Paul.

Reply via email to