Compare commits

...
5 Commits
Author SHA1 Message Date
Glease fda24ff453 Add javadoc on what the patch does
Signed-off-by: Glease <[email protected]>
2021-01-30 13:27:25 -08:00
Glease 42445c61e7 Merge OreDictBandAid fix
https://github.com/Glease/OreDictBandAid

Signed-off-by: Glease <[email protected]>
2021-01-30 13:27:25 -08:00
Jason Mitchell 3bb7b6722a Fixes thread starvation issue with parallelStream in findFuels() being called from within another parallelStream on the same ForkJoinPool
Introduces a `findFuelsOnceParallel` that is called before the parallel recipe/usage handlers are run (which now call the non parallel version of findFuels())
2021-01-30 12:38:45 -08:00
Jason Mitchell 03ede1773c Backwards Compat
* Some mods (GC, for example) rely on FuelPair in FurnaceRecipeHandler so add it back as deprecated and switch to TemplateFuelPair
2021-01-17 14:57:58 -08:00
Jason Mitchell f534b6ed0d Some reorganization and bugfixes
* Moved findFuels to TemplateRecipeHandler and made it thread safe.
* Several for loops -> streams
* Slight refactor on Item Filtering.execute()
2021-01-17 14:05:11 -08:00
11 changed files with 295 additions and 78 deletions

No files matched your search

+1 -1
View File
@@ -2,4 +2,4 @@ mc_version=1.7.10
forge_version=10.13.4.1614-1.7.10
ccl_version=1.1.3.138
ccc_version=1.0.7.+
mod_version=2.0.6-GTNH
mod_version=2.0.8-GTNH
+6 -10
View File
@@ -18,6 +18,7 @@ import java.util.List;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ForkJoinPool;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
public class ItemList
{
@@ -245,20 +246,15 @@ public class ItemList
@Override
public void execute() {
// System.out.println("Executing NEI Item Filtering");
ArrayList<ItemStack> filtered = new ArrayList<>();
ArrayList<ItemStack> filtered;
ItemFilter filter = getItemListFilter();
try {
ItemList.forkJoinPool.submit(() -> items.parallelStream().forEach(item -> {
if (interrupted()) return;
if(filter.matches(item)) {
synchronized (filtered){
filtered.add(item);
}
}
})).get();
filtered = ItemList.forkJoinPool.submit(() -> items.parallelStream()
.filter(filter::matches)
.collect(Collectors.toCollection(ArrayList::new))).get();
} catch (InterruptedException | ExecutionException e) {
filtered = new ArrayList<>();
e.printStackTrace();
stop();
}
+11 -8
View File
@@ -15,6 +15,8 @@ import codechicken.lib.asm.ModularASMTransformer.MethodWriter;
import codechicken.lib.asm.ObfMapping;
import cpw.mods.fml.relauncher.FMLLaunchHandler;
import net.minecraft.launchwrapper.IClassTransformer;
import org.objectweb.asm.ClassReader;
import org.objectweb.asm.ClassWriter;
import org.objectweb.asm.Type;
import org.objectweb.asm.tree.ClassNode;
import org.objectweb.asm.tree.FieldInsnNode;
@@ -31,13 +33,7 @@ import static codechicken.lib.asm.InsnComparator.getControlFlowLabels;
import static codechicken.lib.asm.InsnComparator.matches;
import static org.objectweb.asm.ClassWriter.COMPUTE_FRAMES;
import static org.objectweb.asm.ClassWriter.COMPUTE_MAXS;
import static org.objectweb.asm.Opcodes.ACC_PUBLIC;
import static org.objectweb.asm.Opcodes.ACC_STATIC;
import static org.objectweb.asm.Opcodes.ALOAD;
import static org.objectweb.asm.Opcodes.ILOAD;
import static org.objectweb.asm.Opcodes.INVOKESPECIAL;
import static org.objectweb.asm.Opcodes.INVOKEVIRTUAL;
import static org.objectweb.asm.Opcodes.IRETURN;
import static org.objectweb.asm.Opcodes.*;
public class NEITransformer implements IClassTransformer
{
@@ -259,8 +255,15 @@ public class NEITransformer implements IClassTransformer
public byte[] transform(String name, String tname, byte[] bytes) {
if (bytes == null) return null;
try {
if (FMLLaunchHandler.side().isClient())
if (FMLLaunchHandler.side().isClient()) {
if (name.equals("net.minecraftforge.oredict.OreDictionary")) {
ClassReader cr = new ClassReader(bytes);
ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_FRAMES);
cr.accept(new OreDictionaryVisitor(ASM5, cw), ClassReader.SKIP_DEBUG | ClassReader.SKIP_FRAMES);
bytes = cw.toByteArray();
}
bytes = transformSubclasses(name, bytes);
}
bytes = transformer.transform(name, bytes);
} catch (Exception e) {
@@ -0,0 +1,147 @@
package codechicken.nei.asm;
import static org.objectweb.asm.Opcodes.*;
import codechicken.nei.NEIClientConfig;
import org.objectweb.asm.ClassVisitor;
import org.objectweb.asm.Label;
import org.objectweb.asm.MethodVisitor;
/**
* Code without this patch
* <pre>
public class OreDictionary {
public static int getOreID(String name) {
Integer val = nameToId.get(name);
if (val == null)
{
idToName.add(name);
val = idToName.size() - 1; //0 indexed
nameToId.put(name, val);
idToStack.add(new ArrayList<ItemStack>());
idToStackUn.add(new UnmodifiableArrayList(idToStack.get(val)));
}
return val;
}
}
</pre>
Code with this patch
<pre>
public class OreDictionary {
private static final Object emptyEntryCreationLock = new Object();
public static int getOreID(String name) {
Integer val = nameToId.get(name);
if (val == null)
{
synchronized (emptyEntryCreationLock) {
if ((val = nameToId.get(name)) != null)
return val;
idToName.add(name);
val = idToName.size() - 1; //0 indexed
nameToId.put(name, val);
idToStack.add(new ArrayList<ItemStack>());
idToStackUn.add(new UnmodifiableArrayList(idToStack.get(val)));
}
}
return val;
}
}
* </pre>
*/
public class OreDictionaryVisitor extends ClassVisitor {
private static class GetOreIDVisitor extends MethodVisitor {
Label jumpEnd;
Label catchStart = new Label();
Label exitStart = new Label();
public GetOreIDVisitor(int api, MethodVisitor mv) {
super(api, mv);
}
@Override
public void visitJumpInsn(int opcode, Label label) {
super.visitJumpInsn(opcode, label);
NEIClientConfig.logger.trace("Adding getOreID MONITERENTER");
jumpEnd = label;
mv.visitFieldInsn(GETSTATIC, "net/minecraftforge/oredict/OreDictionary", "emptyEntryCreationLock", "Ljava/lang/Object;");
mv.visitInsn(MONITORENTER);
mv.visitLabel(catchStart);
mv.visitFieldInsn(GETSTATIC, "net/minecraftforge/oredict/OreDictionary", "nameToId", "Ljava/util/Map;");
mv.visitVarInsn(ALOAD, 0);
mv.visitMethodInsn(INVOKEINTERFACE, "java/util/Map", "get", "(Ljava/lang/Object;)Ljava/lang/Object;", true);
mv.visitTypeInsn(CHECKCAST, "java/lang/Integer");
mv.visitVarInsn(ASTORE, 1);
mv.visitVarInsn(ALOAD, 1);
mv.visitJumpInsn(IFNONNULL, exitStart);
}
@Override
public void visitLabel(Label label) {
if (label.equals(jumpEnd)) {
NEIClientConfig.logger.trace("Adding getOreID MONITEREXIT");
// normal exit
mv.visitLabel(exitStart);
mv.visitFieldInsn(GETSTATIC, "net/minecraftforge/oredict/OreDictionary", "emptyEntryCreationLock", "Ljava/lang/Object;");
mv.visitInsn(MONITOREXIT);
// not normal
mv.visitJumpInsn(GOTO, jumpEnd);
Label catchBegin = new Label();
mv.visitLabel(catchBegin);
mv.visitFieldInsn(GETSTATIC, "net/minecraftforge/oredict/OreDictionary", "emptyEntryCreationLock", "Ljava/lang/Object;");
mv.visitInsn(MONITOREXIT);
mv.visitInsn(ATHROW);
// try-catch block metadata
mv.visitTryCatchBlock(catchStart, catchBegin, catchBegin, null);
}
super.visitLabel(label);
}
@Override
public void visitEnd() {
super.visitEnd();
}
}
private static class ClassInitializerVisitor extends MethodVisitor{
public ClassInitializerVisitor(int api, MethodVisitor mv) {
super(api, mv);
}
@Override
public void visitCode() {
super.visitCode();
NEIClientConfig.logger.trace("Adding emptyEntryCreationLock initializer");
mv.visitTypeInsn(NEW, "java/lang/Object");
mv.visitInsn(DUP);
mv.visitMethodInsn(INVOKESPECIAL, "java/lang/Object", "<init>", "()V", false);
mv.visitFieldInsn(PUTSTATIC, "net/minecraftforge/oredict/OreDictionary","emptyEntryCreationLock", "Ljava/lang/Object;");
}
@Override
public void visitEnd() {
super.visitEnd();
}
}
public OreDictionaryVisitor(int api, ClassVisitor cv) {
super(api, cv);
}
@Override
public void visitEnd() {
NEIClientConfig.logger.debug("Adding emptyEntryCreationLock");
cv.visitField(ACC_PRIVATE | ACC_STATIC | ACC_FINAL, "emptyEntryCreationLock", "Ljava/lang/Object;", null, null);
super.visitEnd();
}
@Override
public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) {
if (name.equals("getOreID") && desc.equals("(Ljava/lang/String;)I")) {
NEIClientConfig.logger.debug("Patching getOreID");
return new GetOreIDVisitor(api, super.visitMethod(access, name, desc, signature, exceptions));
} else if (name.equals("<clinit>")) {
// some classes don't have clinit. not this one.
NEIClientConfig.logger.debug("Patching clinit");
return new ClassInitializerVisitor(api, super.visitMethod(access, name, desc, signature, exceptions));
}
return super.visitMethod(access, name, desc, signature, exceptions);
}
}
@@ -92,19 +92,23 @@ public class BrewingRecipeHandler extends TemplateRecipeHandler
public void loadCraftingRecipes(ItemStack result) {
if (result.getItem() != potionitem) return;
int damage = result.getItemDamage();
for (BrewingRecipe recipe : apotions)
if (recipe.result.item.getItemDamage() == damage)
arecipes.add(new CachedBrewingRecipe(recipe));
// Note: Not safe as written for parallelStream
apotions.stream()
.filter(recipe -> recipe.result.item.getItemDamage() == damage)
.map(CachedBrewingRecipe::new)
.collect(Collectors.toCollection(() -> arecipes));
}
@Override
public void loadUsageRecipes(ItemStack ingredient) {
if (ingredient.getItem() != potionitem && !ingredients.contains(ingredient)) return;
for (BrewingRecipe recipe : apotions)
if (NEIServerUtils.areStacksSameType(recipe.ingredient.item, ingredient) || NEIServerUtils.areStacksSameType(recipe.precursorPotion.item, ingredient))
arecipes.add(new CachedBrewingRecipe(recipe));
// Note: Not safe as written for parallelStream
apotions.stream()
.filter(recipe -> NEIServerUtils.areStacksSameType(recipe.ingredient.item, ingredient) || NEIServerUtils.areStacksSameType(recipe.precursorPotion.item, ingredient))
.map(CachedBrewingRecipe::new)
.collect(Collectors.toCollection(() -> arecipes));
}
@Override
@@ -9,6 +9,7 @@ import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.stream.Collectors;
import static codechicken.nei.NEIClientUtils.translate;
@@ -16,9 +17,9 @@ public class FuelRecipeHandler extends FurnaceRecipeHandler
{
public class CachedFuelRecipe extends CachedRecipe
{
public final FuelPair fuel;
public final TemplateFuelPair fuel;
public CachedFuelRecipe(FuelPair fuel) {
public CachedFuelRecipe(TemplateFuelPair fuel) {
this.fuel = fuel;
}
@@ -49,24 +50,32 @@ public class FuelRecipeHandler extends FurnaceRecipeHandler
return NEIClientUtils.translate("recipe.fuel");
}
@SuppressWarnings("unchecked")
private void loadAllSmelting() {
Map<ItemStack, ItemStack> recipes = (Map<ItemStack, ItemStack>) FurnaceRecipes.smelting().getSmeltingList();
for (Entry<ItemStack, ItemStack> recipe : recipes.entrySet())
mfurnace.add(new SmeltingPair(recipe.getKey(), recipe.getValue()));
// Note: Not safe as written for parallelStream
final Map<ItemStack, ItemStack> smeltingRecipes = (Map<ItemStack, ItemStack>) FurnaceRecipes.smelting().getSmeltingList();
smeltingRecipes.entrySet().stream()
.map(recipe -> new SmeltingPair(recipe.getKey(), recipe.getValue()))
.collect(Collectors.toCollection(() -> mfurnace));
}
@Override
public void loadCraftingRecipes(String outputId, Object... results) {
// Note: Not safe as written for parallelStream
if (outputId.equals("fuel") && getClass() == FuelRecipeHandler.class)
for (FuelPair fuel : afuels)
arecipes.add(new CachedFuelRecipe(fuel));
afuels.stream()
.map(CachedFuelRecipe::new)
.collect(Collectors.toCollection(() -> arecipes));
}
public void loadUsageRecipes(ItemStack ingredient) {
for (FuelPair fuel : afuels)
if (fuel.stack != null && fuel.stack.contains(ingredient))
arecipes.add(new CachedFuelRecipe(fuel));
// Note: Not safe as written for parallelStream
afuels.stream()
.filter(fuel -> fuel != null && fuel.stack != null && fuel.stack.contains(ingredient))
.map(CachedFuelRecipe::new)
.collect(Collectors.toCollection(() -> arecipes));
}
public String getOverlayIdentifier() {
@@ -76,7 +85,7 @@ public class FuelRecipeHandler extends FurnaceRecipeHandler
@Override
public List<String> handleItemTooltip(GuiRecipe gui, ItemStack stack, List<String> currenttip, int recipe) {
CachedFuelRecipe crecipe = (CachedFuelRecipe) arecipes.get(recipe);
FuelPair fuel = crecipe.fuel;
TemplateFuelPair fuel = crecipe.fuel;
float burnTime = fuel.burnTime / 200F;
if (gui.isMouseOver(fuel.stack, recipe) && burnTime < 1) {
@@ -1,26 +1,18 @@
package codechicken.nei.recipe;
import codechicken.nei.ItemList;
import codechicken.nei.NEIClientUtils;
import codechicken.nei.NEIServerUtils;
import codechicken.nei.PositionedStack;
import net.minecraft.block.Block;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.client.gui.inventory.GuiFurnace;
import net.minecraft.init.Blocks;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.FurnaceRecipes;
import net.minecraft.tileentity.TileEntityFurnace;
import java.awt.Rectangle;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
public class FurnaceRecipeHandler extends TemplateRecipeHandler
{
@@ -48,8 +40,8 @@ public class FurnaceRecipeHandler extends TemplateRecipeHandler
final PositionedStack result;
}
public static class FuelPair
{
@Deprecated
public static class FuelPair {
public FuelPair(ItemStack ingred, int burnTime) {
this.stack = new PositionedStack(ingred, 51, 42, false);
this.burnTime = burnTime;
@@ -59,8 +51,6 @@ public class FurnaceRecipeHandler extends TemplateRecipeHandler
public final int burnTime;
}
public static ArrayList<FuelPair> afuels;
public static HashSet<Block> efuels;
@Override
public void loadTransferRects() {
@@ -80,8 +70,9 @@ public class FurnaceRecipeHandler extends TemplateRecipeHandler
@Override
public TemplateRecipeHandler newInstance() {
if (afuels == null || afuels.isEmpty())
findFuels();
// Use the non parallel version since we might already be using the forkJoinPool and might have no threads available
// This will ideally have been pre-cached elsewhere and will be a NOOP
findFuelsOnce();
return super.newInstance();
}
@@ -133,27 +124,6 @@ public class FurnaceRecipeHandler extends TemplateRecipeHandler
drawProgressBar(74, 23, 176, 14, 24, 16, 48, 0);
}
private static Set<Item> excludedFuels() {
Set<Item> efuels = new HashSet<>();
efuels.add(Item.getItemFromBlock(Blocks.brown_mushroom));
efuels.add(Item.getItemFromBlock(Blocks.red_mushroom));
efuels.add(Item.getItemFromBlock(Blocks.standing_sign));
efuels.add(Item.getItemFromBlock(Blocks.wall_sign));
efuels.add(Item.getItemFromBlock(Blocks.wooden_door));
efuels.add(Item.getItemFromBlock(Blocks.trapped_chest));
return efuels;
}
private static void findFuels() {
afuels = new ArrayList<>();
Set<Item> efuels = excludedFuels();
for (ItemStack item : ItemList.items)
if (!efuels.contains(item.getItem())) {
int burnTime = TileEntityFurnace.getItemBurnTime(item);
if (burnTime > 0)
afuels.add(new FuelPair(item.copy(), burnTime));
}
}
@Override
public String getOverlayIdentifier() {
@@ -5,7 +5,6 @@ import codechicken.nei.ItemList;
import codechicken.nei.NEIClientUtils;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.client.gui.inventory.GuiContainer;
import java.util.ArrayList;
import java.util.concurrent.ExecutionException;
@@ -19,8 +18,12 @@ public class GuiCraftingRecipe extends GuiRecipe
ArrayList<ICraftingHandler> handlers;
TaskProfiler profiler = ProfilerRecipeHandler.getProfiler();
profiler.start("recipe.concurrent.crafting");
// Pre-find the fuels so we're not fighting over it
FuelRecipeHandler.findFuelsOnceParallel();
try {
profiler.start("recipe.concurrent.crafting");
handlers = ItemList.forkJoinPool.submit(() -> craftinghandlers.parallelStream()
.map(h -> h.getRecipeHandler(outputId, results))
.filter(h -> h.numRecipes() > 0)
@@ -18,8 +18,12 @@ public class GuiUsageRecipe extends GuiRecipe
ArrayList<IUsageHandler> handlers;
TaskProfiler profiler = ProfilerRecipeHandler.getProfiler();
// Pre-find the fuels so we're not fighting over it
FuelRecipeHandler.findFuelsOnceParallel();
profiler.start("recipe.concurrent.usage");
try {
profiler.start("recipe.concurrent.usage");
handlers = ItemList.forkJoinPool.submit(() -> usagehandlers.parallelStream()
.map(h -> h.getUsageHandler(inputId, ingredients))
.filter(h -> h.numRecipes() > 0)
@@ -154,7 +154,7 @@ public class ShapedRecipeHandler extends TemplateRecipeHandler
Object[] items = recipe.getInput();
for (Object item : items)
if (item instanceof List && ((List<?>) item).isEmpty())//ore handler, no ores
if (item instanceof List && ((List<?>) item).isEmpty()) //ore handler, no ores
return null;
return new CachedShapedRecipe(width, height, items, recipe.getRecipeOutput());
@@ -1,5 +1,6 @@
package codechicken.nei.recipe;
import codechicken.nei.ItemList;
import codechicken.nei.NEIClientConfig;
import codechicken.nei.NEIClientUtils;
import codechicken.nei.NEIServerUtils;
@@ -11,11 +12,14 @@ import codechicken.nei.api.IStackPositioner;
import codechicken.nei.guihook.GuiContainerManager;
import codechicken.nei.guihook.IContainerInputHandler;
import codechicken.nei.guihook.IContainerTooltipHandler;
import com.google.common.base.Stopwatch;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.init.Blocks;
import net.minecraft.inventory.Container;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntityFurnace;
import org.lwjgl.opengl.GL11;
import java.awt.Point;
@@ -26,7 +30,12 @@ import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Objects;
import java.util.Random;
import java.util.Set;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.locks.ReentrantLock;
import java.util.stream.Collectors;
import static codechicken.lib.gui.GuiDraw.changeTexture;
import static codechicken.lib.gui.GuiDraw.drawTexturedModalRect;
@@ -41,6 +50,75 @@ import static codechicken.lib.gui.GuiDraw.getMousePosition;
*/
public abstract class TemplateRecipeHandler implements ICraftingHandler, IUsageHandler
{
protected static ReentrantLock lock = new ReentrantLock();
public static class TemplateFuelPair
{
public TemplateFuelPair(ItemStack ingred, int burnTime) {
this.stack = new PositionedStack(ingred, 51, 42, false);
this.burnTime = burnTime;
}
public final PositionedStack stack;
public final int burnTime;
}
public static List<TemplateFuelPair> afuels;
public static void findFuelsOnce() {
// Ensure we only find fuels once, even if threaded
lock.lock();
try {
if (afuels == null || afuels.isEmpty())
findFuels(false);
} finally {
lock.unlock();
}
}
public static void findFuelsOnceParallel() {
// Ensure we only find fuels once, even if threaded
lock.lock();
try {
if (afuels == null || afuels.isEmpty())
findFuels(true);
} finally {
lock.unlock();
}
}
private static Set<Item> efuels;
@SuppressWarnings("UnstableApiUsage")
private static void findFuels(boolean parallel) {
efuels = new HashSet<>();
efuels.add(Item.getItemFromBlock(Blocks.brown_mushroom));
efuels.add(Item.getItemFromBlock(Blocks.red_mushroom));
efuels.add(Item.getItemFromBlock(Blocks.standing_sign));
efuels.add(Item.getItemFromBlock(Blocks.wall_sign));
efuels.add(Item.getItemFromBlock(Blocks.wooden_door));
efuels.add(Item.getItemFromBlock(Blocks.trapped_chest));
Stopwatch stopwatch = Stopwatch.createStarted();
if (parallel) {
try {
afuels = ItemList.forkJoinPool.submit(() -> ItemList.items.parallelStream().map(TemplateRecipeHandler::identifyFuel).filter(Objects::nonNull).collect(Collectors.toList())).get();
} catch (InterruptedException | ExecutionException e) {
afuels = new ArrayList<>();
e.printStackTrace();
}
} else {
afuels = ItemList.items.stream().map(TemplateRecipeHandler::identifyFuel).filter(Objects::nonNull).collect(Collectors.toList());
}
NEIClientConfig.logger.info("FindFuels took " + stopwatch.stop() );
}
private static TemplateFuelPair identifyFuel(final ItemStack itemStack) {
if (efuels.contains(itemStack.getItem())) return null;
final int burnTime = TileEntityFurnace.getItemBurnTime(itemStack);
if (burnTime <= 0) return null;
return new TemplateFuelPair(itemStack.copy(), burnTime);
}
/**
* This Recipe Handler runs on this internal class
* Fill the recipe array with subclasses of this to make transforming the different types of recipes out there into a nice format for NEI a much easier job.
@@ -310,7 +388,7 @@ public abstract class TemplateRecipeHandler implements ICraftingHandler, IUsageH
*/
public ArrayList<CachedRecipe> arecipes = new ArrayList<>();
/**
* A list of transferRects that apon when clicked or R is pressed will open a new recipe.
* A list of transferRects that when clicked or R is pressed will open a new recipe.
*/
public LinkedList<RecipeTransferRect> transferRects = new LinkedList<>();
@@ -463,6 +541,9 @@ public abstract class TemplateRecipeHandler implements ICraftingHandler, IUsageH
public TemplateRecipeHandler newInstance() {
try {
// Use the non parallel version since we might already be using the forkJoinPool and might have no threads available
// This will ideally have been pre-cached elsewhere and will be a NOOP
findFuelsOnce();
return getClass().newInstance();
} catch (Exception e) {
throw new RuntimeException(e);