Re: Why are page faults used for safe point polling instead of other signals?

2020-05-29 Thread Steven Stewart-Gallus
teven Stewart-Gallus wrote: > > Okay I have an idea. > I can't shake the idea you could do fun tricks with thread local > executable pages. > > The theoretically fastest way of safepoint polling is inserting a trap > instruction. But icache overheads dominate. If the icache is

Re: Why are page faults used for safe point polling instead of other signals?

2020-05-29 Thread Steven Stewart-Gallus
Okay I have an idea. I can't shake the idea you could do fun tricks with thread local executable pages. The theoretically fastest way of safepoint polling is inserting a trap instruction. But icache overheads dominate. If the icache is based on physical addresses and not virtual ones then it sh

Re: Best way to dynamically spin Java classes?

2020-05-21 Thread Steven Stewart-Gallus
; On Thu, May 7, 2020 at 14:47, Steven Stewart-Gallus < > stevensele...@gmail.com > wrote: > >> Hi, >> >> Just going to update this thread with a link to the repo I am asking this >> question for which I finally see fit to share >> https://github.com/sstewar

Re: Why are page faults used for safe point polling instead of other signals?

2020-05-18 Thread Steven Stewart-Gallus
t;. Are there public benchmarks on real world software? Has anything changed on recent hardware? It seems the obviously fastest way to cause a fault but what if it is not? Thanks Steven Stewart-Gallus On Mon., May 18, 2020, 9:04 a.m. Gil Tene, wrote: > This is an evolving and ever-explored field... &g

Why are page faults used for safe point polling instead of other signals?

2020-05-17 Thread Steven Stewart-Gallus
Hi As I understand it most VMs poll for safepoints by using memory management tricks to page fault polling threads. A page is set aside to read from and whenever a safepoint is desired the page is set to be unreadable. But can't a number of other hardware traps be used instead https://wiki.osde

Re: Best way to dynamically spin Java classes?

2020-05-07 Thread Steven Stewart-Gallus
some of you might be interested in this kind of bytecode spinning stuff. On Sunday, April 26, 2020 at 9:36:07 AM UTC-7, Steven Stewart-Gallus wrote: > > I'm spinning a lot of classes dynamically for an interpreter. > I'm not sure the best way to load the classes into the VM. > >

Re: Best way to dynamically spin Java classes?

2020-05-01 Thread Steven Stewart-Gallus
pathy" > > *Envoyé: *Dimanche 26 Avril 2020 19:11:53 > *Objet: *Re: Best way to dynamically spin Java classes? > > In Java 15 we will have hidden classes, which seem like the right model > for what you are trying to do. > > On Sun, 26 Apr 2020 at 19:36, Steven Stewa

Re: How to convert a DynamicConstantDesc to a MethodHandle?

2020-04-30 Thread Steven Stewart-Gallus
resolve(MethodHandles.Lookup lookup) throws ReflectiveOperationException { if (null == result) { result = desc.resolveConstantDesc(lookup); } return result; } } On Thursday, April 30, 2020 at 6:57:19 PM UTC-7, Steven Stewart-Gallus wrote: > > Hello, &g

How to convert a DynamicConstantDesc to a MethodHandle?

2020-04-30 Thread Steven Stewart-Gallus
ivate finals in lambda objects to do this but I'm not quite certain that would work. Thanks Steven Stewart-Gallus -- You received this message because you are subscribed to the Google Groups "mechanical-sympathy" group. To unsubscribe from this group and stop receiving ema

Best way to dynamically spin Java classes?

2020-04-26 Thread Steven Stewart-Gallus
I'm spinning a lot of classes dynamically for an interpreter. I'm not sure the best way to load the classes into the VM. Aside from Unsafe's defineAnonymousClass what's the best way to load classes into the VM? I believe I could create a new classloader for each spun class but IIRC classloaders

Re: Volatile semantic for failed/noop atomic operations

2019-10-05 Thread Steven Stewart-Gallus
Couldn't you do a compare and compare and swap? With VarHandles something like if (ACTION.getOpaque(this) != expected) return false; return compareAndExchange(this, expected, newValue) == expected; Not sure I got this correct On Saturday, September 14, 2019 at 11:29:00 AM UTC-7, Vitaly Davidovi

Re: Exotic classes

2019-05-23 Thread Steven Stewart-Gallus
Figured out something bizarre about combining lambdas just the other day. Code like static EqualsSupport makeEquals(Set> getters) { EqualsSupport equals = (a, b) -> true; for (var getter : getters) { if (getter instanceof ObjectGetter) { var g = (ObjectGetter) getter;

Re: Exotic classes

2019-05-16 Thread Steven Stewart-Gallus
Hi, For a long while, I couldn't think of what to reply with. I just don't feel the problem of grouping fields together deserves to distort the API that much. I guess part of the problem is Java doesn't support a syntax for field references (even though VarHandleDesc are already implemented.) It

Re: Exotic classes

2019-04-26 Thread Steven Stewart-Gallus
'd inevitably end up needing more support methods such as a toString method. On Friday, April 26, 2019 at 8:13:17 AM UTC-7, Remi Forax wrote: > > > > -------------- > > *De: *"Steven Stewart-Gallus" > > *À: *"mechanical-sympathy"

Re: Exotic classes

2019-04-25 Thread Steven Stewart-Gallus
1. Why public abstract class ObjectSupport { public abstract boolean equals(Object self, Object other); public abstract int hashCode(); public static ObjectSupport of(Lookup lookup, String... fields) { // impl details } // impl details } and not something like? interf

Re: Avoid stepping on page faults while writing to MappedByteBuffer

2019-03-30 Thread Steven Stewart-Gallus
I feel like this is just a bug in the JDK that should be patched. Couldn't this all be solved by replacing UNSAFE.copyMemory with a call to a different method that isn't a HotSpot intrinsic? https://hg.openjdk.java.net/jdk/jdk/file/235883996bc7/src/java.base/share/classes/java/nio/Direct-X-Buffe

Re: Do modern JVMs use aliasing information?

2019-01-28 Thread Steven Stewart-Gallus
Ahah! I believe I might have a possible hacky workaround! Instead of doing: static void mul(int[] accum, int accumOffset, int[] src, int srcOffset, int n) { for (int ii = 0; ii < n; ++ii) { accum[ii + accumOffset] *= src[ii + srcOffset]; } } do static void mul(int[] accum, int

Re: Do modern JVMs use aliasing information?

2019-01-20 Thread Steven Stewart-Gallus
I found a much more complete reference (also by Vladimir Ivanov it seems) but it may be out of date (it's from 2017.) http://cr.openjdk.java.net/~vlivanov/talks/2017_Vectorization_in_HotSpot_JVM.pdf -- You received this message because you are subscribed to the Google Groups "mechanical-sympat

Re: Do modern JVMs use aliasing information?

2019-01-20 Thread Steven Stewart-Gallus
I see, so the same doesn't apply to read only workflow though right? private static int dot(int[] heap, int n, int a, int b) { var sum = 0; for (var ii = 0; ii < n; ++ii) { sum += heap[a + ii] * heap[b + ii]; } return sum; } And one last question. Can VarHandle byte arra

Re: likely and unlikely macros

2019-01-19 Thread Steven Stewart-Gallus
You can use a MutableCallSite with MethodHandles.constant if you really need to to create "mostly final" variables. In addition null checks are heavily optimised by the JVM to use segmentation faults and so can be slightly faster than boolean checks sometimes. As well, JVM inlining handle this

Re: Sorting a very large number of objects

2019-01-19 Thread Steven Stewart-Gallus
I'm really confused. You're talking about putting the data into sqlite which suggests there really isn't so much log data and it could be filtered with a hacky shell script. But then you're talking about a lot of heavy optimisation which suggests you really may need to put in custom effort. Pre

Do modern JVMs use aliasing information?

2019-01-19 Thread Steven Stewart-Gallus
It is well known that compilers can't optimise things as well if values may alias. Because src and dest may overlap: public static void multiply(int[] accum, int accumOffset, int[] src, int srcOffset, int n){ for (var ii = 0; ii < n; ++ii) { dest[ii] *= src[ii]; } } does not hav

Re: Happens before between putting and getting from and to ConcurrentHashMap

2019-01-19 Thread Steven Stewart-Gallus
Seriously no. Just use a VarHandle fence -- You received this message because you are subscribed to the Google Groups "mechanical-sympathy" group. To unsubscribe from this group and stop receiving emails from it, send an email to mechanical-sympathy+unsubscr...@googlegroups.com. For more option

Re: Exotic classes

2019-01-18 Thread Steven Stewart-Gallus
On Friday, January 18, 2019 at 5:37:58 AM UTC-8, Rémi Forax wrote > > no, CHA only works on class, not on interface. > > You're probably know better than me. I seem to remember there's something like that for interfaces but very limited such as if you ever only have ever one implementation. I s

Re: Avoid stepping on page faults while writing to MappedByteBuffer

2019-01-16 Thread Steven Stewart-Gallus
I think what you want is something like the mincore system call on Linux so your thread can write directly if the page is mapped but offload the work to another thread if it is not mapped. I don't have any experience with the system call though. -- You received this message because you are sub

Re: FlatBuffers, ByteBuffers, and escape analysis

2019-01-16 Thread Steven Stewart-Gallus
Is there any reason you can't just manually pack the bytes together? public int getInt(byte[]buf, int ix){ return buf[ix] | buf[ix + 1] << 8 | buf[ix + 2] << 16 | buf[ix + 3] << 24; } It should be kind of slow but probably less so than a bunch of allocations -- You received this message be

Re: Exotic classes

2019-01-16 Thread Steven Stewart-Gallus
I've been working on similar issues trying to optimise something heavily. I made a similar class to this one (I even had a similar API) but I found I called it MostlyFinal instead. private static final MostlyConstant FOO = new MostlyConstant<>(42, int.class); private static final IntSupplier F

Re: LOCK XADD wait-free or lock free.

2019-01-16 Thread Steven Stewart-Gallus
There are more than a few ways to Denial of Service other threads and or cores on most personal computers today. Of which the most common way encountered is to probably use up too much memory causing the system to swap to the hard drive. This is partly a feature not a bug. You wouldn't like a s