Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8308088

Improve class check in CollectedHeap::is_oop

    XMLWordPrintable

Details

    • Enhancement
    • Resolution: Fixed
    • P4
    • 21
    • 11, 17, 20, 21
    • hotspot
    • b23

    Description

      (Found this during Lilliput review)

      Current CollectedHeap::is_oop is weird:

      ```
      bool CollectedHeap::is_oop(oop object) const {
      ...
        if (is_in(object->klass_raw())) { // <--- if klass is in the Java heap, it is not an oop?!
          return false;
        }
      ...
      }
      ```

      The history shows it goes all the way back to JDK-6964458, which rewrote the previous checking code to:

      ```
      @@ -589,21 +609,7 @@ inline bool oopDesc::is_oop(bool ignore_mark_word) const {
         if (!check_obj_alignment(obj)) return false;
         if (!Universe::heap()->is_in_reserved(obj)) return false;
         // obj is aligned and accessible in heap
      - // try to find metaclass cycle safely without seg faulting on bad input
      - // we should reach klassKlassObj by following klass link at most 3 times
      - for (int i = 0; i < 3; i++) {
      - obj = obj->klass_or_null();
      - // klass should be aligned and in permspace
      - if (!check_obj_alignment(obj)) return false;
      - if (!Universe::heap()->is_in_permanent(obj)) return false;
      - }
      - if (obj != Universe::klassKlassObj()) {
      - // During a dump, the _klassKlassObj moved to a shared space.
      - if (DumpSharedSpaces && Universe::klassKlassObj()->is_shared()) {
      - return true;
      - }
      - return false;
      - }
      + if (Universe::heap()->is_in_reserved(obj->klass_or_null())) return false;
      ```

      I think the check should be a more direct: assert the klass ptr is in the Metaspace, at very least.

      Attachments

        Issue Links

          Activity

            People

              shade Aleksey Shipilev
              shade Aleksey Shipilev
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: