Shenandoah: Re-design alloc request type enum for better efficiency and cleaner code

XMLWordPrintable

    • gc

      Current alloc request type enum:
      ```
        enum Type {
          _alloc_shared, // Allocate common, outside of TLAB
          _alloc_shared_gc, // Allocate common, outside of GCLAB/PLAB
          _alloc_cds, // Allocate for CDS
          _alloc_tlab, // Allocate TLAB
          _alloc_gclab, // Allocate GCLAB
          _alloc_plab, // Allocate PLAB
          _ALLOC_LIMIT
        };

      ```

      With current enum design, we have to impl functions is_mutator_alloc, is_gc_alloc and is_lab_alloc with switch, which may also result in larger machine code and more code branches, we could design the enum values for request type to void this and make the code much simpler, for example:

      ```
        enum Type {
          _alloc_shared = 2, // Allocate common, outside of TLAB
          _alloc_cds = 4, // Allocate for CDS
          _alloc_tlab = 5, // Allocate TLAB
          _alloc_shared_gc = 6, // Allocate common, outside of GCLAB/PLAB
          _alloc_gclab = 7, // Allocate GCLAB
          _alloc_plab = 9 // Allocate PLAB
        };
      ```

      1. Odd value for lab alloc, even value for shared and cds;
      2. mutator alloc type <= _alloc_tlab and gc alloc type >= _alloc_shared_gc;
      3. _ALLOC_LIMIT is not used at all, remove it.

      With the design, the three methods will be like:
      ```
        inline bool is_mutator_alloc() const {
          return _alloc_type <= _alloc_tlab;
        }

        inline bool is_gc_alloc() const {
          return _alloc_type >= _alloc_shared_gc;
        }

        inline bool is_lab_alloc() const {
          return (_alloc_type & 1) == 1;
        }
      ```

      Here is the original code for comparsion:
      ```
        inline bool is_mutator_alloc() const {
          switch (_alloc_type) {
            case _alloc_tlab:
            case _alloc_shared:
            case _alloc_cds:
              return true;
            case _alloc_gclab:
            case _alloc_plab:
            case _alloc_shared_gc:
              return false;
            default:
              ShouldNotReachHere();
              return false;
          }
        }

        inline bool is_gc_alloc() const {
          switch (_alloc_type) {
            case _alloc_tlab:
            case _alloc_shared:
            case _alloc_cds:
              return false;
            case _alloc_gclab:
            case _alloc_plab:
            case _alloc_shared_gc:
              return true;
            default:
              ShouldNotReachHere();
              return false;
          }
        }

        inline bool is_lab_alloc() const {
          switch (_alloc_type) {
            case _alloc_tlab:
            case _alloc_gclab:
            case _alloc_plab:
              return true;
            case _alloc_shared:
            case _alloc_shared_gc:
            case _alloc_cds:
              return false;
            default:
              ShouldNotReachHere();
              return false;
          }
        }
      ```

            Assignee:
            Xiaolong Peng
            Reporter:
            Xiaolong Peng
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated: