Path: blob/master/src/hotspot/share/jfr/utilities/jfrPredicate.hpp
41149 views
/*1* Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*22*/2324#ifndef SHARE_JFR_UTILITIES_JFRPREDICATE_HPP25#define SHARE_JFR_UTILITIES_JFRPREDICATE_HPP2627#include "memory/allocation.hpp"28#include "utilities/growableArray.hpp"2930/*31* Premise is that the set is sorted.32*/33template <typename T, int cmp(const T&, const T&)>34class JfrPredicate : AllStatic {35public:36static bool test(GrowableArray<T>* set, T value) {37assert(set != NULL, "invariant");38bool found = false;39set->template find_sorted<T, cmp>(value, found);40return found;41}42};4344/*45* Premise is that the set is sorted.46*/47template <typename T, int cmp(const T&, const T&)>48class JfrMutablePredicate : AllStatic {49public:50static bool test(GrowableArray<T>* set, T value) {51assert(set != NULL, "invariant");52bool found = false;53const int location = set->template find_sorted<T, cmp>(value, found);54if (!found) {55set->insert_before(location, value);56}57return found;58}59};6061#endif // SHARE_JFR_UTILITIES_JFRPREDICATE_HPP626364