Comparisons of 'this' to NULL are bogus because the compiler is free to elide these tests. Since (this == NULL) can never be true; applying an ordinary member function to NULL invokes undefined behavior.
Here are the places in the JVM that compare 'this' to NULL (based in part on email from Matthias Baesken):
jdk/src/hotspot/share/adlc/formssel.cpp
1727bool Opcode::print_opcode(FILE *fp, Opcode::opcode_type desired_opcode) {
1728 // Default values previously provided by MachNode::primary()...
1729 const char *description = NULL;
1730 const char *value = NULL;
1731 // Check if user provided any opcode definitions
1732 if( this != NULL ) {
3417void MatchNode::count_instr_names( Dict &names ) {
3418 if( this == NULL ) return;
jdk/src/hotspot/share/opto/chaitin.cpp
2147char *PhaseChaitin::dump_register( const Node *n, char *buf ) const {
2148 if( this == NULL ) { // Not got anything?
2149 sprintf(buf,"N%d",n->_idx); // Then use Node index
2150 } else if( _node_regs ) {
jdk/src/hotspot/share/asm/codeBuffer.cpp
1241void CodeBuffer::print() {
1242 if (this == NULL) {
1243 tty->print_cr("NULL CodeBuffer pointer");
jdk/src/hotspot/share/libadt/set.cpp
58char *Set::setstr() const
59{
60 if( this == NULL ) return os::strdup("{no set}");
Here are the places in the JVM that compare 'this' to NULL (based in part on email from Matthias Baesken):
jdk/src/hotspot/share/adlc/formssel.cpp
1727bool Opcode::print_opcode(FILE *fp, Opcode::opcode_type desired_opcode) {
1728 // Default values previously provided by MachNode::primary()...
1729 const char *description = NULL;
1730 const char *value = NULL;
1731 // Check if user provided any opcode definitions
1732 if( this != NULL ) {
3417void MatchNode::count_instr_names( Dict &names ) {
3418 if( this == NULL ) return;
jdk/src/hotspot/share/opto/chaitin.cpp
2147char *PhaseChaitin::dump_register( const Node *n, char *buf ) const {
2148 if( this == NULL ) { // Not got anything?
2149 sprintf(buf,"N%d",n->_idx); // Then use Node index
2150 } else if( _node_regs ) {
jdk/src/hotspot/share/asm/codeBuffer.cpp
1241void CodeBuffer::print() {
1242 if (this == NULL) {
1243 tty->print_cr("NULL CodeBuffer pointer");
jdk/src/hotspot/share/libadt/set.cpp
58char *Set::setstr() const
59{
60 if( this == NULL ) return os::strdup("{no set}");
- duplicates
-
JDK-8209087 Clean up runtime code that compares 'this' to NULL
-
- Resolved
-