JDK-8160742 : Node::operator new invokes undefined behavior
  • Type: Bug
  • Component: hotspot
  • Sub-Component: compiler
  • Affected Version: 9
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2016-07-02
  • Updated: 2018-02-15
  • Resolved: 2016-07-27
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.
JDK 9
9 b131Fixed
Related Reports
Duplicate :  
Relates :  
Description
Node::operator new looks like:

inline void* operator new(size_t x) throw() {
   Compile* C = Compile::current();
   Node* n = (Node*)C->node_arena()->Amalloc_D(x);
#ifdef ASSERT
   n->_in = (Node**)n; // magic cookie for assertion check
#endif
   return (void*)n;
 }

That assignment of n->_in is, in this context, undefined behavior.  Applying member access (either data or function) to storage before the constructor has been applied to it (or after the destructor) is undefined behavior.
Comments
This assert code isn't even useful anymore, since JDK-7193318.
22-07-2016

ILW = possible undefined behavior in product source code; new operator overloads are affected; none = MMH = P3
05-07-2016

I've noticed several other similar issues. Unfortunately, I haven't been keeping a list. An audit of operator new definitions is likely needed. I think all of them that I've noticed were in compiler code, but I'm not at all certain of that.
02-07-2016

gcc6 will discard the offending statement, since it invokes undefined behavior, and that leads to an assertion failure later. This compiler behavior can be suppressed using -fno-lifetime-dse, at least for gcc, but other compilers might make similar decisions. It would be better to fix the code.
02-07-2016