8196199: Remove miscellaneous oop comparison operators
authorcoleenp
Thu, 01 Feb 2018 13:30:53 -0500
changeset 48831 05894c073b7e
parent 48830 11920d5d14a8
child 48832 f1e8ddd6fdc4
8196199: Remove miscellaneous oop comparison operators Reviewed-by: hseigel, lfoltan Contributed-by: kim.barrett@oracle.com, coleen.phillimore@oracle.com
src/hotspot/share/code/oopRecorder.cpp
src/hotspot/share/gc/cms/concurrentMarkSweepGeneration.hpp
src/hotspot/share/gc/parallel/parMarkBitMap.cpp
src/hotspot/share/oops/oop.hpp
src/hotspot/share/oops/oopsHierarchy.hpp
src/hotspot/share/prims/jniCheck.cpp
src/hotspot/share/services/threadService.cpp
--- a/src/hotspot/share/code/oopRecorder.cpp	Wed Jan 31 17:43:46 2018 -0800
+++ b/src/hotspot/share/code/oopRecorder.cpp	Thu Feb 01 13:30:53 2018 -0500
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1998, 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1998, 2018, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -172,9 +172,8 @@
 }
 
 int ObjectLookup::sort_by_address(oop a, oop b) {
-  if (b > a) return 1;
-  if (a > b) return -1;
-  return 0;
+  // oopDesc::compare returns the opposite of what this function returned
+  return -(oopDesc::compare(a, b));
 }
 
 int ObjectLookup::sort_by_address(ObjectEntry* a, ObjectEntry* b) {
--- a/src/hotspot/share/gc/cms/concurrentMarkSweepGeneration.hpp	Wed Jan 31 17:43:46 2018 -0800
+++ b/src/hotspot/share/gc/cms/concurrentMarkSweepGeneration.hpp	Thu Feb 01 13:30:53 2018 -0500
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2001, 2017, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2001, 2018, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -246,11 +246,11 @@
 
   // Compute the least valued stack element.
   oop least_value(HeapWord* low) {
-     oop least = (oop)low;
-     for (size_t i = 0; i < _index; i++) {
-       least = MIN2(least, _base[i]);
-     }
-     return least;
+    HeapWord* least = low;
+    for (size_t i = 0; i < _index; i++) {
+      least = MIN2(least, (HeapWord*)_base[i]);
+    }
+    return (oop)least;
   }
 
   // Exposed here to allow stack expansion in || case.
--- a/src/hotspot/share/gc/parallel/parMarkBitMap.cpp	Wed Jan 31 17:43:46 2018 -0800
+++ b/src/hotspot/share/gc/parallel/parMarkBitMap.cpp	Thu Feb 01 13:30:53 2018 -0500
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2005, 2017, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2005, 2018, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -131,26 +131,28 @@
 }
 
 size_t
-ParMarkBitMap::live_words_in_range_use_cache(ParCompactionManager* cm, HeapWord* beg_addr, oop end_obj) const
+ParMarkBitMap::live_words_in_range_use_cache(ParCompactionManager* cm, HeapWord* beg_addr, oop end_oop) const
 {
   HeapWord* last_beg = cm->last_query_begin();
-  oop last_obj = cm->last_query_object();
+  HeapWord* last_obj = (HeapWord*)cm->last_query_object();
+  HeapWord* end_obj  = (HeapWord*)end_oop;
+
   size_t last_ret = cm->last_query_return();
   if (end_obj > last_obj) {
-    last_ret = last_ret + live_words_in_range_helper((HeapWord*)last_obj, end_obj);
+    last_ret = last_ret + live_words_in_range_helper(last_obj, end_oop);
     last_obj = end_obj;
   } else if (end_obj < last_obj) {
     // The cached value is for an object that is to the left (lower address) of the current
     // end_obj. Calculate back from that cached value.
-    if (pointer_delta((HeapWord*)end_obj, (HeapWord*)beg_addr) > pointer_delta((HeapWord*)last_obj, (HeapWord*)end_obj)) {
-      last_ret = last_ret - live_words_in_range_helper((HeapWord*)end_obj, last_obj);
+    if (pointer_delta(end_obj, beg_addr) > pointer_delta(last_obj, end_obj)) {
+      last_ret = last_ret - live_words_in_range_helper(end_obj, (oop)last_obj);
     } else {
-      last_ret = live_words_in_range_helper(beg_addr, end_obj);
+      last_ret = live_words_in_range_helper(beg_addr, end_oop);
     }
     last_obj = end_obj;
   }
 
-  update_live_words_in_range_cache(cm, last_beg, last_obj, last_ret);
+  update_live_words_in_range_cache(cm, last_beg, (oop)last_obj, last_ret);
   return last_ret;
 }
 
--- a/src/hotspot/share/oops/oop.hpp	Wed Jan 31 17:43:46 2018 -0800
+++ b/src/hotspot/share/oops/oop.hpp	Thu Feb 01 13:30:53 2018 -0500
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2018, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -143,6 +143,21 @@
   inline static bool is_null(oop obj)       { return obj == NULL; }
   inline static bool is_null(narrowOop obj) { return obj == 0; }
 
+  // Standard compare function returns negative value if o1 < o2
+  //                                   0              if o1 == o2
+  //                                   positive value if o1 > o2
+  inline static int  compare(oop o1, oop o2) {
+    void* o1_addr = (void*)o1;
+    void* o2_addr = (void*)o2;
+    if (o1_addr < o2_addr) {
+      return -1;
+    } else if (o1_addr > o2_addr) {
+      return 1;
+    } else {
+      return 0;
+    }
+  }
+
   // Decode an oop pointer from a narrowOop if compressed.
   // These are overloaded for oop and narrowOop as are the other functions
   // below so that they can be called in template functions.
--- a/src/hotspot/share/oops/oopsHierarchy.hpp	Wed Jan 31 17:43:46 2018 -0800
+++ b/src/hotspot/share/oops/oopsHierarchy.hpp	Thu Feb 01 13:30:53 2018 -0500
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2018, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -106,12 +106,6 @@
   bool operator!=(const volatile oop o) const  { return obj() != o.obj(); }
   bool operator!=(void *p) const      { return obj() != p; }
 
-  bool operator<(oop o) const         { return obj() < o.obj(); }
-  bool operator>(oop o) const         { return obj() > o.obj(); }
-  bool operator<=(oop o) const        { return obj() <= o.obj(); }
-  bool operator>=(oop o) const        { return obj() >= o.obj(); }
-  bool operator!() const              { return !obj(); }
-
   // Assignment
   oop& operator=(const oop& o)                            { _o = o.obj(); return *this; }
   volatile oop& operator=(const oop& o) volatile          { _o = o.obj(); return *this; }
--- a/src/hotspot/share/prims/jniCheck.cpp	Wed Jan 31 17:43:46 2018 -0800
+++ b/src/hotspot/share/prims/jniCheck.cpp	Thu Feb 01 13:30:53 2018 -0500
@@ -288,7 +288,7 @@
   /* validate the object being passed and then get its class */
   ASSERT_OOPS_ALLOWED;
   oop oopObj = jniCheck::validate_object(thr, obj);
-  if (!oopObj) {
+  if (oopObj == NULL) {
     ReportJNIFatalError(thr, fatal_null_object);
   }
   Klass* k_oop = oopObj->klass();
@@ -318,7 +318,7 @@
 {
   ASSERT_OOPS_ALLOWED;
   oop s = jniCheck::validate_object(thr, js);
-  if (!s || !java_lang_String::is_instance(s))
+  if ((s == NULL) || !java_lang_String::is_instance(s))
     ReportJNIFatalError(thr, fatal_non_string);
 }
 
@@ -461,14 +461,13 @@
 
 
 oop jniCheck::validate_object(JavaThread* thr, jobject obj) {
-    if (!obj)
-        return NULL;
-    ASSERT_OOPS_ALLOWED;
-    oop oopObj = jniCheck::validate_handle(thr, obj);
-    if (!oopObj) {
-      ReportJNIFatalError(thr, fatal_bad_ref_to_jni);
-    }
-    return oopObj;
+  if (obj == NULL) return NULL;
+  ASSERT_OOPS_ALLOWED;
+  oop oopObj = jniCheck::validate_handle(thr, obj);
+  if (oopObj == NULL) {
+    ReportJNIFatalError(thr, fatal_bad_ref_to_jni);
+  }
+  return oopObj;
 }
 
 // Warn if a class descriptor is in decorated form; class descriptors
@@ -492,7 +491,7 @@
 Klass* jniCheck::validate_class(JavaThread* thr, jclass clazz, bool allow_primitive) {
   ASSERT_OOPS_ALLOWED;
   oop mirror = jniCheck::validate_handle(thr, clazz);
-  if (!mirror) {
+  if (mirror == NULL) {
     ReportJNIFatalError(thr, fatal_received_null_class);
   }
 
--- a/src/hotspot/share/services/threadService.cpp	Wed Jan 31 17:43:46 2018 -0800
+++ b/src/hotspot/share/services/threadService.cpp	Thu Feb 01 13:30:53 2018 -0500
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2003, 2017, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -489,7 +489,7 @@
       _locked_monitors = new (ResourceObj::C_HEAP, mtInternal) GrowableArray<oop>(length, true);
       for (int i = 0; i < length; i++) {
         MonitorInfo* monitor = list->at(i);
-        assert(monitor->owner(), "This monitor must have an owning object");
+        assert(monitor->owner() != NULL, "This monitor must have an owning object");
         _locked_monitors->append(monitor->owner());
       }
     }