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

Support C++ lambda in ResourceHashtable::iterate

XMLWordPrintable

    • b26

      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).

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

              Created:
              Updated:
              Resolved: