Path: blob/master/test/hotspot/jtreg/vmTestbase/vm/compiler/complog/uninit/UninitializedTrapCounter.java
41161 views
/*1* Copyright (c) 2013, 2018, 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*/22package vm.compiler.complog.uninit;2324import java.util.*;25import java.util.regex.*;26import java.io.*;2728import nsk.share.TestFailure;29import vm.compiler.complog.share.LogCompilationParser;3031/**32* Parser that finds uninitialized traps for each method and throws33* and exception if there are more then 1 uninitialized trap for at least 1 method.34*35* Parser supports following options:36* <ul>37* <li>-classFilter=<comma separated list> - list of classes for which uncommon traps will be checked. If option is not presented or list is empty then all uncommon traps for all classes will be checked.38* <li>-methodFilter=<comma separated list> - list of methods for which uncommon traps will be checked. If option is not presented or list is empty then all uncommon traps for all methods will be checked.39* </ul>40* If compilation log contains uncommon trap with reason uninialized that was fired for method M in class K, then it will be checked only if classFilter contains K and methodFilter contains M.41*/42public class UninitializedTrapCounter extends LogCompilationParser {43private Map<String,Integer> methods = new LinkedHashMap<String,Integer>();4445private static final String JVMS_ELEMENT = "<jvms [^>]*>";46private static final String METHOD_INFO = "method='(([^ ']+) ([^ ']+) [^']+)'.*uninitialized_traps='([0-9]+)'";47private static final String CLASS_FILTER = "-classFilter=([^ ]+)";48private static final String METHOD_FILTER = "-methodFilter=([^ ]+)";49private static Pattern pattern = Pattern.compile(METHOD_INFO);5051private List<String> classFilter = new ArrayList<String>();52private List<String> methodFilter = new ArrayList<String>();5354public void setOptions(String optionString) {55if(optionString == null) return;56Matcher methodFilterMatcher = Pattern.compile(METHOD_FILTER).matcher(optionString);57Matcher classFilterMatcher = Pattern.compile(CLASS_FILTER).matcher(optionString);58if(methodFilterMatcher.find()) {59methodFilter = Arrays.asList(methodFilterMatcher.group(1).split(","));60}61if(classFilterMatcher.find()) {62classFilter = Arrays.asList(classFilterMatcher.group(1).split(","));63}64}6566/**67* Find uninitialized traps count.68*/69public void parse(File logFile) throws Throwable {70Scanner scanner = new Scanner(logFile);71String jvms = scanner.findWithinHorizon(JVMS_ELEMENT,0);72while(jvms != null) {73parseJVMSElement(jvms);74jvms = scanner.findWithinHorizon(JVMS_ELEMENT,0);75}7677boolean failed = false;78for(Map.Entry<String,Integer> method : methods.entrySet()) {79if(method.getValue() > 1) {80failed = true;81log.error(method.getValue() +82" uninitizlied traps found for method '" +83method.getKey() + "'.");8485}86}87if(failed) {88throw new TestFailure("More than 1 uncommon trap with reason 'uninitialized'"+89" occurred at least for 1 method.");90}91}9293private void parseJVMSElement(String jvms) {94Matcher matcher = pattern.matcher(jvms);95if(!matcher.find()) return;9697String methodID = matcher.group(1);98String trapsCountStr = matcher.group(4);99Integer trapsCount = 0;100Integer oldTrapsCount = 0;101String className = matcher.group(2);102String methodName = matcher.group(3);103104if((classFilter.size() > 0 && !findMatches(classFilter,className)) ||105(methodFilter.size() > 0 && !findMatches(methodFilter,methodName))) {106//filtering out uncommon trap we are not interested in107return;108}109110try {111trapsCount = Integer.valueOf(trapsCountStr);112} catch (NumberFormatException nfe) {113trapsCount = 0;114}115116oldTrapsCount = methods.get(methodID);117if(oldTrapsCount == null) oldTrapsCount = -1;118119methods.put(methodID, Math.max(trapsCount, oldTrapsCount));120}121122private static boolean findMatches(List<String> patterns, String str) {123for(String pattern : patterns) {124if(Pattern.matches(pattern,str)) {125return true;126}127}128return false;129}130131}132133134