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

Support C++ lambda in ResourceHashtable::iterate

    XMLWordPrintable

    Details

    • Type: Enhancement
    • Status: Resolved
    • Priority: P4
    • Resolution: Fixed
    • Affects Version/s: 18
    • Fix Version/s: 19
    • Component/s: hotspot
    • Subcomponent:
    • Resolved In Build:
      b26

      Description

      Maybe something like this in resourceHash.hpp:

        template<class ITER>
        void iterate(ITER* iter) const { // the old API
          auto f = [&] (K& k, V& v) {
            return iter->do_entry(k, v);
          };
          iterate(f);
        }

        template<typename F>
        void iterate(F f) const { // lambda enabled API
          Node* const* bucket = table();
          const unsigned sz = table_size();
          while (bucket < bucket_at(sz)) {
            Node* node = *bucket;
            while (node != NULL) {
              bool cont = f(node->_key, node->_value);
              if (!cont) { return; }
              node = node->_next;
            }
            ++bucket;
          }
        }

      ==================
      Example usage in heapShared.cpp

          int n = 0;
          auto f = [&] (oop& k, oop& v) {
            n++;
            return true;
          };
          archived_object_cache()->iterate(f);
          tty->print_cr("Counted = %d objects", n);
      ==================
      Need to verify that there's no performance degradation in the code generated by modern C++ compilers (when either old or new API is used).

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              iklam Ioi Lam
              Reporter:
              iklam Ioi Lam
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: