< prev index next >

src/java.base/share/classes/jdk/internal/foreign/abi/ShuffleRecipeBuilder.java

Print this page

        

*** 1,7 **** /* ! * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. --- 1,7 ---- /* ! * Copyright (c) 2015, 2019, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation.
*** 22,53 **** */ package jdk.internal.foreign.abi; import jdk.internal.foreign.Util; import java.util.ArrayList; class ShuffleRecipeBuilder { - private final ShuffleRecipeOperationCollector arguments = new ShuffleRecipeOperationCollector(); - private final ShuffleRecipeOperationCollector returns = new ShuffleRecipeOperationCollector(); ! ShuffleRecipeBuilder() { } ! ShuffleRecipeOperationCollector getArgumentsCollector() { ! return arguments; } ! ShuffleRecipeOperationCollector getReturnsCollector() { ! return returns; } ! private int getTotalNumberOfOps() { ! return arguments.getTotalNumberOfOps() + returns.getTotalNumberOfOps(); } private long[] allocArray() { ! long nOpBits = getTotalNumberOfOps() * ShuffleRecipeOperation.BITS_PER_OP; long nOpWords = nOpBits / 64; long nBits = nOpBits + nOpWords; // MSB in each word is reserved nBits = Util.alignUp(nBits, 64); --- 22,67 ---- */ package jdk.internal.foreign.abi; import jdk.internal.foreign.Util; import java.util.ArrayList; + import java.util.HashMap; + import java.util.List; + import java.util.Map; class ShuffleRecipeBuilder { ! List<ShuffleRecipeOperation> ops = new ArrayList<>(); ! Map<ArgumentBinding, Long> offsets = new HashMap<>(); ! int nArgPulls; ! int nRetPulls; ! ! void addSkip() { ! ops.add(ShuffleRecipeOperation.SKIP); } ! void addStop() { ! ops.add(ShuffleRecipeOperation.STOP); } ! void addPulls(boolean isReturn, long n) { ! for (long i = 0; i < n; i++) { ! ops.add(ShuffleRecipeOperation.PULL); ! if (isReturn) { ! nRetPulls++; ! } else { ! nArgPulls++; ! } ! } } ! void addOffset(ArgumentBinding binding, long offset) { ! offsets.put(binding, offset); } private long[] allocArray() { ! long nOpBits = ops.size() * ShuffleRecipeOperation.BITS_PER_OP; long nOpWords = nOpBits / 64; long nBits = nOpBits + nOpWords; // MSB in each word is reserved nBits = Util.alignUp(nBits, 64);
*** 78,116 **** for (int i = 0; i < arr.length; i++) { arr[i] = (1L << 63); } int i = 0; ! for (ArrayList<ShuffleRecipeOperation> oparr : arguments.getOps()) { ! for (ShuffleRecipeOperation op : oparr) { ! encodeOp(arr, i++, op); ! } ! encodeOp(arr, i++, ShuffleRecipeOperation.STOP); ! } ! for (ArrayList<ShuffleRecipeOperation> oparr : returns.getOps()) { ! for (ShuffleRecipeOperation op : oparr) { encodeOp(arr, i++, op); } - encodeOp(arr, i++, ShuffleRecipeOperation.STOP); - } return arr; } ShuffleRecipe build() { ! return new ShuffleRecipe(recipeToLongArray(), getArgumentsCollector().getNoofPulls(), getReturnsCollector().getNoofPulls()); } public String asString() { StringBuilder sb = new StringBuilder(); sb.append("ShuffleRecipe: {\n"); ! sb.append(" Arguments: {\n"); ! sb.append(arguments.asString().indent(4)); ! sb.append(" }\n"); ! sb.append(" Returns: {\n"); ! sb.append(returns.asString().indent(4)); sb.append(" }\n"); sb.append("}\n"); return sb.toString(); } --- 92,119 ---- for (int i = 0; i < arr.length; i++) { arr[i] = (1L << 63); } int i = 0; ! ! for (ShuffleRecipeOperation op : ops) { encodeOp(arr, i++, op); } return arr; } ShuffleRecipe build() { ! return new ShuffleRecipe(recipeToLongArray(), nArgPulls, nRetPulls, offsets); } public String asString() { StringBuilder sb = new StringBuilder(); sb.append("ShuffleRecipe: {\n"); ! sb.append(" Operations: {\n"); ! sb.append(ops); sb.append(" }\n"); sb.append("}\n"); return sb.toString(); }
< prev index next >