Dieser Commit ist enthalten in:
Jesse Boyd 2019-11-02 12:51:24 +01:00
Ursprung df9e9e510a
Commit 6ed7923a1e
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 59F1DE6293AF6E1F
7 geänderte Dateien mit 129 neuen und 57 gelöschten Zeilen

Datei anzeigen

@ -105,21 +105,25 @@ public enum FaweCache implements Trimable {
@Override @Override
public synchronized boolean trim(boolean aggressive) { public synchronized boolean trim(boolean aggressive) {
CHUNK_FLAG.clean(); if (aggressive) {
BYTE_BUFFER_8192.clean(); CleanableThreadLocal.cleanAll();
BLOCK_TO_PALETTE.clean(); } else {
PALETTE_TO_BLOCK.clean(); CHUNK_FLAG.clean();
BLOCK_STATES.clean(); BYTE_BUFFER_8192.clean();
SECTION_BLOCKS.clean(); BLOCK_TO_PALETTE.clean();
PALETTE_CACHE.clean(); PALETTE_TO_BLOCK.clean();
PALETTE_TO_BLOCK_CHAR.clean(); BLOCK_STATES.clean();
INDEX_STORE.clean(); SECTION_BLOCKS.clean();
PALETTE_CACHE.clean();
PALETTE_TO_BLOCK_CHAR.clean();
INDEX_STORE.clean();
MUTABLE_VECTOR3.clean(); MUTABLE_VECTOR3.clean();
MUTABLE_BLOCKVECTOR3.clean(); MUTABLE_BLOCKVECTOR3.clean();
SECTION_BITS_TO_CHAR.clean(); SECTION_BITS_TO_CHAR.clean();
for (Map.Entry<Class, CleanableThreadLocal> entry : REGISTERED_SINGLETONS.entrySet()) { for (Map.Entry<Class, CleanableThreadLocal> entry : REGISTERED_SINGLETONS.entrySet()) {
entry.getValue().clean(); entry.getValue().clean();
}
} }
for (Map.Entry<Class, Pool> entry : REGISTERED_POOLS.entrySet()) { for (Map.Entry<Class, Pool> entry : REGISTERED_POOLS.entrySet()) {
Pool pool = entry.getValue(); Pool pool = entry.getValue();

Datei anzeigen

@ -5,7 +5,10 @@ import com.boydti.fawe.util.MainUtil;
import java.lang.ref.Reference; import java.lang.ref.Reference;
import java.lang.reflect.Array; import java.lang.reflect.Array;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.atomic.LongAdder; import java.util.concurrent.atomic.LongAdder;
import java.util.function.Consumer; import java.util.function.Consumer;
import java.util.function.Function; import java.util.function.Function;
@ -51,25 +54,47 @@ public class CleanableThreadLocal<T> extends ThreadLocal<T> {
} }
} }
public static void clean(ThreadLocal instance) { public List<T> getAll() {
List<T> list = new ArrayList<>();
iterate(this, new Consumer<Object>() {
Method methodGetEntry;
Field fieldValue;
@Override
public void accept(Object tlm) {
try {
if (methodGetEntry == null) {
methodGetEntry = tlm.getClass().getDeclaredMethod("getEntry", ThreadLocal.class);
methodGetEntry.setAccessible(true);
}
Object entry = methodGetEntry.invoke(tlm, CleanableThreadLocal.this);
if (entry != null) {
if (fieldValue == null) {
fieldValue = entry.getClass().getDeclaredField("value");
fieldValue.setAccessible(true);
}
Object value = fieldValue.get(entry);
if (value != null) {
list.add((T) value);
}
}
} catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException | NoSuchFieldException e) {
throw new RuntimeException(e);
}
}
});
return list;
}
public static void iterate(ThreadLocal instance, Consumer<Object> withMap) {
try { try {
Thread[] threads = MainUtil.getThreads(); Thread[] threads = MainUtil.getThreads();
Field tl = Thread.class.getDeclaredField("threadLocals"); Field tl = Thread.class.getDeclaredField("threadLocals");
tl.setAccessible(true); tl.setAccessible(true);
Method methodRemove = null;
for (Thread thread : threads) { for (Thread thread : threads) {
if (thread != null) { if (thread != null) {
Object tlm = tl.get(thread); Object tlm = tl.get(thread);
if (tlm != null) { if (tlm != null) {
if (methodRemove == null) { withMap.accept(tlm);
methodRemove = tlm.getClass().getDeclaredMethod("remove", ThreadLocal.class);
methodRemove.setAccessible(true);
}
if (methodRemove != null) {
try {
methodRemove.invoke(tlm, instance);
} catch (Throwable ignore) {}
}
} }
} }
} }
@ -78,6 +103,29 @@ public class CleanableThreadLocal<T> extends ThreadLocal<T> {
} }
} }
public static void clean(ThreadLocal instance) {
iterate(instance, new Consumer<Object>() {
Method methodRemove;
@Override
public void accept(Object tlm) {
try {
if (methodRemove == null) {
methodRemove = tlm.getClass().getDeclaredMethod("remove", ThreadLocal.class);
methodRemove.setAccessible(true);
}
if (methodRemove != null) {
try {
methodRemove.invoke(tlm, instance);
} catch (Throwable ignore) {
}
}
} catch (NoSuchMethodException e) {
throw new RuntimeException(e);
}
}
});
}
public static void cleanAll() { public static void cleanAll() {
try { try {
// Get a reference to the thread locals table of the current thread // Get a reference to the thread locals table of the current thread

Datei anzeigen

@ -1,6 +1,7 @@
package com.boydti.fawe.object.extent; package com.boydti.fawe.object.extent;
import com.boydti.fawe.FaweCache; import com.boydti.fawe.FaweCache;
import com.boydti.fawe.beta.IBatchProcessor;
import com.boydti.fawe.beta.IChunk; import com.boydti.fawe.beta.IChunk;
import com.boydti.fawe.beta.IChunkGet; import com.boydti.fawe.beta.IChunkGet;
import com.boydti.fawe.beta.IChunkSet; import com.boydti.fawe.beta.IChunkSet;
@ -34,7 +35,7 @@ import java.util.List;
import java.util.Set; import java.util.Set;
import javax.annotation.Nullable; import javax.annotation.Nullable;
public class NullExtent extends FaweRegionExtent { public class NullExtent extends FaweRegionExtent implements IBatchProcessor {
private final FaweException reason; private final FaweException reason;
@ -328,11 +329,16 @@ public class NullExtent extends FaweRegionExtent {
@Override @Override
public IChunkSet processSet(IChunk chunk, IChunkGet get, IChunkSet set) { public IChunkSet processSet(IChunk chunk, IChunkGet get, IChunkSet set) {
return null; throw reason;
} }
@Override @Override
public boolean processGet(int chunkX, int chunkZ) { public boolean processGet(int chunkX, int chunkZ) {
return false; throw reason;
}
@Override
public Extent construct(Extent child) {
throw reason;
} }
} }

Datei anzeigen

@ -332,6 +332,7 @@ public class EditSession extends PassthroughExtent implements AutoCloseable {
if (get instanceof AbstractDelegateExtent && !(get instanceof NullExtent)) { if (get instanceof AbstractDelegateExtent && !(get instanceof NullExtent)) {
traverser.setNext(nullExtent); traverser.setNext(nullExtent);
} }
get.addProcessor(nullExtent);
traverser = next; traverser = next;
} }
return super.cancel(); return super.cancel();

Datei anzeigen

@ -25,6 +25,7 @@ import com.boydti.fawe.object.brush.visualization.VirtualWorld;
import com.boydti.fawe.object.clipboard.DiskOptimizedClipboard; import com.boydti.fawe.object.clipboard.DiskOptimizedClipboard;
import com.boydti.fawe.regions.FaweMaskManager; import com.boydti.fawe.regions.FaweMaskManager;
import com.boydti.fawe.util.MainUtil; import com.boydti.fawe.util.MainUtil;
import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.EmptyClipboardException; import com.sk89q.worldedit.EmptyClipboardException;
import com.sk89q.worldedit.IncompleteRegionException; import com.sk89q.worldedit.IncompleteRegionException;
import com.sk89q.worldedit.LocalSession; import com.sk89q.worldedit.LocalSession;
@ -40,6 +41,7 @@ import com.sk89q.worldedit.math.Vector3;
import com.sk89q.worldedit.regions.Region; import com.sk89q.worldedit.regions.Region;
import com.sk89q.worldedit.regions.RegionSelector; import com.sk89q.worldedit.regions.RegionSelector;
import com.sk89q.worldedit.session.ClipboardHolder; import com.sk89q.worldedit.session.ClipboardHolder;
import com.sk89q.worldedit.session.request.Request;
import com.sk89q.worldedit.util.Direction; import com.sk89q.worldedit.util.Direction;
import com.sk89q.worldedit.util.HandSide; import com.sk89q.worldedit.util.HandSide;
import com.sk89q.worldedit.util.Location; import com.sk89q.worldedit.util.Location;
@ -50,6 +52,7 @@ import com.sk89q.worldedit.world.gamemode.GameMode;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import java.io.File; import java.io.File;
import java.io.IOException;
/** /**
* Represents a player * Represents a player
@ -381,32 +384,36 @@ public interface Player extends Entity, Actor {
} }
default int cancel(boolean close) { default int cancel(boolean close) {
// Collection<IQueueExtent> queues = SetQueue.IMP.getAllQueues(); TODO NOT IMPLEMENTED int cancelled = 0;
// int cancelled = 0;
// clearActions(); for (Request request : Request.getAll()) {
// for (IQueueExtent queue : queues) { EditSession editSession = request.getEditSession();
// Collection<EditSession> sessions = queue.getEditSessions(); if (editSession != null) {
// for (EditSession session : sessions) { Player player = editSession.getPlayer();
// FawePlayer currentPlayer = session.getPlayer(); if (equals(player)) {
// if (currentPlayer == this) { editSession.cancel();
// if (session.cancel()) { cancelled++;
// cancelled++; }
// } }
// } }
// } VirtualWorld world = getSession().getVirtualWorld();
// } if (world != null) {
// VirtualWorld world = getSession().getVirtualWorld(); if (close) {
// if (world != null) { try {
// if (close) { world.close(false);
// try { } catch (IOException e) {
// world.close(false); e.printStackTrace();
// } catch (IOException e) { }
// e.printStackTrace(); }
// } else {
// } try {
// else world.clear(); world.close(false);
// } } catch (IOException e) {
return 0; e.printStackTrace();
}
}
}
return cancelled;
} }
void sendTitle(String title, String sub); void sendTitle(String title, String sub);

Datei anzeigen

@ -630,6 +630,7 @@ public final class PlatformCommandManager {
Command cmd = optional.get(); Command cmd = optional.get();
CommandQueuedCondition queued = cmd.getCondition().as(CommandQueuedCondition.class).orElse(null); CommandQueuedCondition queued = cmd.getCondition().as(CommandQueuedCondition.class).orElse(null);
if (queued != null && !queued.isQueued()) { if (queued != null && !queued.isQueued()) {
System.out.println("Not queued");
handleCommandOnCurrentThread(event); handleCommandOnCurrentThread(event);
return; return;
} }
@ -728,8 +729,7 @@ public final class PlatformCommandManager {
} else { } else {
System.out.println("Invalid context " + context); System.out.println("Invalid context " + context);
} }
Optional<EditSession> editSessionOpt = Optional<EditSession> editSessionOpt = context.injectedValue(Key.of(EditSession.class));
context.injectedValue(Key.of(EditSession.class));
if (editSessionOpt.isPresent()) { if (editSessionOpt.isPresent()) {
EditSession editSession = editSessionOpt.get(); EditSession editSession = editSessionOpt.get();

Datei anzeigen

@ -19,6 +19,7 @@
package com.sk89q.worldedit.session.request; package com.sk89q.worldedit.session.request;
import com.boydti.fawe.object.collection.CleanableThreadLocal;
import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.LocalSession; import com.sk89q.worldedit.LocalSession;
import com.sk89q.worldedit.extension.platform.Actor; import com.sk89q.worldedit.extension.platform.Actor;
@ -26,13 +27,14 @@ import com.sk89q.worldedit.extent.Extent;
import com.sk89q.worldedit.world.World; import com.sk89q.worldedit.world.World;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import java.util.List;
/** /**
* Describes the current request using a {@link ThreadLocal}. * Describes the current request using a {@link ThreadLocal}.
*/ */
public final class Request { public final class Request {
private static final ThreadLocal<Request> threadLocal = ThreadLocal.withInitial(Request::new); private static final CleanableThreadLocal<Request> threadLocal = new CleanableThreadLocal<>(Request::new);
private @Nullable World world; private @Nullable World world;
private @Nullable Actor actor; private @Nullable Actor actor;
@ -44,6 +46,10 @@ public final class Request {
private Request() { private Request() {
} }
public static List<Request> getAll() {
return threadLocal.getAll();
}
/** /**
* Get the request world. * Get the request world.
* *