Path: blob/master/test/hotspot/jtreg/compiler/compilercontrol/share/pool/PoolHelper.java
41161 views
/*1* Copyright (c) 2015, 2016, 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*/2223package compiler.compilercontrol.share.pool;2425import jdk.test.lib.util.Pair;2627import java.lang.reflect.Executable;28import java.util.ArrayList;29import java.util.List;30import java.util.concurrent.Callable;31import java.util.function.Predicate;32import java.util.stream.Collectors;3334/**35* This is a helper class that provides tests with methods36*/37public class PoolHelper extends MethodHolder {38private static final List<Pair<Executable, Callable<?>>> METHODS;3940/**41* Filters only those methods who belong to Klass or its internal class42* Internal and named as "method" or is a constructor43*/44public static final Predicate<Executable> METHOD_FILTER = executable -> {45String methodName = executable.getName();46String className = executable.getDeclaringClass().getName();47return className.matches(".*(Klass)(\\$Internal)?") &&48(methodName.equals("method") ||49methodName.equals(className)); // if method is <init>50};5152static {53METHODS = new ArrayList<>();54List<MethodHolder> holders = new ArrayList<>();55holders.add(new compiler.compilercontrol.share.pool.sub.Klass());56holders.add(new compiler.compilercontrol.share.pool.sub.KlassDup());57holders.add(new compiler.compilercontrol.share.pool.subpack.Klass());58holders.add(new compiler.compilercontrol.share.pool.subpack.KlassDup());59holders.add(new compiler.compilercontrol.share.pool.sub.Klass.Internal());60holders.add(new compiler.compilercontrol.share.pool.subpack.KlassDup.Internal());61for (MethodHolder holder : holders) {62METHODS.addAll(holder.getAllMethods());63}64}6566/**67* Gets all methods from the pool using specified filter68*69* @param filter method filter70* @return pairs of Executable and appropriate Callable71*/72public List<Pair<Executable, Callable<?>>> getAllMethods(73Predicate<Executable> filter) {74return getAllMethods().stream()75.filter(pair -> filter.test(pair.first))76.collect(Collectors.toList());77}7879/**80* Gets all methods from the pool81*82* @return pairs of Executable and appropriate Callable83*/84@Override85public List<Pair<Executable, Callable<?>>> getAllMethods() {86return METHODS;87}88}899091