JDK-8237073 : [lworld] Need special handling of jlO constructor invocation
  • Type: Bug
  • Component: tools
  • Sub-Component: javac
  • Affected Version: repo-valhalla
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2020-01-14
  • Updated: 2021-07-21
  • Resolved: 2021-07-20
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Other
repo-valhallaFixed
Related Reports
Cloners :  
Relates :  
Relates :  
Description
From http://cr.openjdk.java.net/~briangoetz/valhalla/sov/02-object-model.html:

Object
Because of its role as the root type for all classes, inline and identity, Object shares many characteristics with interfaces. As noted already, there is an inline widening conversion from all inline types to Object.

However, because Object is a concrete class, it is unfortunately possible to instantiate Object directly through its constructor. And because interfaces are inherited, Object can implement neither InlineObject nor IdentityObject ��� but the result of instantiating new Object() must be an instance of an identity type (since there is no point instantiating Object for any other reason.)

Wriggling out of this trap will require some fancy moves. We can start by creating a static factory Object::newIdentity that returns IdentityObject, and then attempt to migrate existing source and binary usages of new Object() towards this using various tools (compiler warnings, JIT magic) ��� and ultimately ���deprecating��� the Object constructor for direct instantiation (by making it protected).
Comments
(Heard from Dan in another channel that this is to be a part of JEP 401)
06-07-2021

Dan, where do you see this work in Javac happening ?? JDK18 ? Valhalla/lworld ?
05-07-2021

We're pursuing an 'Objects.newIdentity()' method for 17. See JDK-8269096. There may be an additional API in the future (perhaps something in IdentityObject?), but for now, it would be fine for javac to compile 'new Object()' to an invocation of 'Objects.newIdentity()'. This should be accompanied by a warning ("Object cannot be instantiated directly; a subclass of Object will be instantiated instead"), with an encouragement to refactor the code.
02-07-2021