Clojure

Some static initialisers still run at compile time if used in type hints

Details

  • Type: Defect Defect
  • Status: Closed Closed
  • Priority: Major Major
  • Resolution: Completed
  • Affects Version/s: None
  • Fix Version/s: Release 1.9
  • Component/s: None
  • Patch:
    Code and Test
  • Approval:
    Ok

Description

AOT compiling on an x86 machine to be run on an ARM machine when a Java dependency has a native component and the class with the native dependency is used in a type hint.

In this situation, the only native library available on the classpath is the ARM dependency, and obviously won't load on the compiling x86 machine. Java libraries tend to load the native dependencies in the static initialiser of the class, which will fail in this situation as the architecture is x86 and the dependencies are ARM, for which reason CLJ-1315 made the change to not run static initialisers at compile time.

This covers a case which didn't come up as part of CLJ-1315, that the same problem occurs if rather than constructing the class, you simply use it as a type hint (which IMO is doubly surprising as something to have a side-effect).

Approach: Don't cause class to load merely from being in a type hint.

Patch: clj-1714-4.patch

This patch has been used in production for over a year with no adverse effects (as has anybody using the clojure-android build of clojure).

Prescreened: Alex Miller

  1. CLJ-1714.patch
    22/Apr/15 2:37 PM
    1 kB
    Adam Clements
  2. clj-1714-4.patch
    28/Sep/16 2:40 PM
    4 kB
    Alex Miller
  3. CLJ-1714-v2.patch
    12/Aug/15 9:12 AM
    3 kB
    Adam Clements
  4. CLJ-1714-v3.patch
    28/Sep/16 2:07 PM
    3 kB
    Michael Blume

Activity

Adam Clements made changes -
Field Original Value New Value
Attachment 0001-Fix-for-type-hinted-classes-loading-static-initialis.patch [ 14077 ]
Adam Clements made changes -
Attachment CLJ-1714.patch [ 14078 ]
Alex Miller made changes -
Approval Triaged [ 10120 ]
Alex Miller made changes -
Labels compiler typehints
Stuart Halloway made changes -
Approval Triaged [ 10120 ] Incomplete [ 10006 ]
Alex Miller made changes -
Approval Incomplete [ 10006 ]
Alex Miller made changes -
Description This is more of the same problem as http://dev.clojure.org/jira/browse/CLJ-1315 (incorporated in 1.7-alphas) but in the specific case that the class with the static initialiser is used in a type hint

AOT compiling on an x86 machine to be run on an ARM machine when a Java dependency has a native component and the class with the native dependency is used in a type hint.

In this situation, the only native library available on the classpath is the ARM dependency, and obviously won't load on the compiling x86 machine. Java libraries tend to load the native dependencies in the static initialiser of the class, which will fail in this situation as the architecture is x86 and the dependencies are ARM, for which reason CLJ-1315 made the change to not run static initialisers at compile time.

This covers a case which didn't come up as part of CLJ-1315, that the same problem occurs if rather than constructing the class, you simply use it as a type hint (which IMO is doubly surprising as something to have a side-effect).

This patch fixes that - happy to try and create a test, but would appreciate some advice on the shape such a test would take - presumably loading a java native library would be undesirable. I could simply check for static initialisers being run, but first would need some agreement that this is universally undesirable at compile time.

I have been using this patch in production for over a year with no adverse effects (as has anybody using the clojure-android build of clojure).
Approval Triaged [ 10120 ]
Stuart Halloway made changes -
Priority Major [ 3 ] Minor [ 4 ]
Adam Clements made changes -
Attachment CLJ-1714-v2.patch [ 14965 ]
Michael Blume made changes -
Attachment CLJ-1714-v3.patch [ 15980 ]
Alex Miller made changes -
Attachment clj-1714-4.patch [ 15983 ]
Description AOT compiling on an x86 machine to be run on an ARM machine when a Java dependency has a native component and the class with the native dependency is used in a type hint.

In this situation, the only native library available on the classpath is the ARM dependency, and obviously won't load on the compiling x86 machine. Java libraries tend to load the native dependencies in the static initialiser of the class, which will fail in this situation as the architecture is x86 and the dependencies are ARM, for which reason CLJ-1315 made the change to not run static initialisers at compile time.

This covers a case which didn't come up as part of CLJ-1315, that the same problem occurs if rather than constructing the class, you simply use it as a type hint (which IMO is doubly surprising as something to have a side-effect).

This patch fixes that - happy to try and create a test, but would appreciate some advice on the shape such a test would take - presumably loading a java native library would be undesirable. I could simply check for static initialisers being run, but first would need some agreement that this is universally undesirable at compile time.

I have been using this patch in production for over a year with no adverse effects (as has anybody using the clojure-android build of clojure).
AOT compiling on an x86 machine to be run on an ARM machine when a Java dependency has a native component and the class with the native dependency is used in a type hint.

In this situation, the only native library available on the classpath is the ARM dependency, and obviously won't load on the compiling x86 machine. Java libraries tend to load the native dependencies in the static initialiser of the class, which will fail in this situation as the architecture is x86 and the dependencies are ARM, for which reason CLJ-1315 made the change to not run static initialisers at compile time.

This covers a case which didn't come up as part of CLJ-1315, that the same problem occurs if rather than constructing the class, you simply use it as a type hint (which IMO is doubly surprising as something to have a side-effect).

*Approach:* Don't cause class to load merely from being in a type hint.

*Patch:* clj-1714-4.patch

This patch has been used in production for over a year with no adverse effects (as has anybody using the clojure-android build of clojure).

*Prescreened:* Alex Miller
Approval Triaged [ 10120 ] Prescreened [ 10220 ]
Patch Code [ 10001 ] Code and Test [ 10002 ]
Alex Miller made changes -
Priority Minor [ 4 ] Major [ 3 ]
Rich Hickey made changes -
Approval Prescreened [ 10220 ] Ok [ 10007 ]
Alex Miller made changes -
Fix Version/s Release 1.9 [ 10750 ]
Stuart Halloway made changes -
Resolution Completed [ 1 ]
Status Open [ 1 ] Closed [ 6 ]

People

Vote (1)
Watch (2)

Dates

  • Created:
    Updated:
    Resolved: