{"content":{"sharePage":{"page":0,"digests":[{"id":"76894495","dateCreated":"1452689584","smartDate":"Jan 13, 2016","userCreated":{"username":"pdigre","url":"https:\/\/www.wikispaces.com\/user\/view\/pdigre","imageUrl":"https:\/\/www.wikispaces.com\/i\/user_none_lg.jpg"},"monitored":false,"locked":false,"links":{"self":"https:\/\/chessprogramming.wikispaces.com\/share\/view\/76894495"},"dateDigested":1531483569,"startDate":null,"sharedType":"discussion","title":"Java 8 - Performance enhancements","description":"I think the "2-10 times slower" disadvantage is disappearing with the Java 7 and 8 dynamic recompilation techniques. Dynamic recompilation can do certain run-time optimizations that a normal compiler cannot.
\nRecently, I was trying to speed-up certain move generation by C and to my surprise it was not getting faster at all. I first believed that I would benefit from mixing in C code using JNI, taking advantage of new processor bit-scanning instructions such as LZCNT, POPCNT etc. Later I found that Java automatically maps the Long library to these bit-scanning instructions. I am not a good C-programmer so I do not make processor-optimizations to the compiler. By avoiding Java performance pitfalls and writing a "high-performance" Java program I tried to see if I could get any of it faster by C. After rewriting my C-program many times I got approximately the same speed for C, but still slower than Java. Performance pitfalls I avoid is such as unnecessary garbage collection, primitives instead of objects where possible, no object arrays, etc.
\n
\nI think we may see a dawn now where dynamic recompilation advantages will outweigh the run-time profiling cost, thus making a well-written Java program even faster than a well-written C-program.","replyPages":[{"page":0,"digests":[],"more":0}]},{"id":"5252299","dateCreated":"1220284057","smartDate":"Sep 1, 2008","userCreated":{"username":"GerdIsenberg","url":"https:\/\/www.wikispaces.com\/user\/view\/GerdIsenberg","imageUrl":"https:\/\/www.wikispaces.com\/user\/pic\/1202793136\/GerdIsenberg-lg.jpg"},"monitored":false,"locked":false,"links":{"self":"https:\/\/chessprogramming.wikispaces.com\/share\/view\/5252299"},"dateDigested":1531483569,"startDate":null,"sharedType":"discussion","title":"unsigned long","description":"- Java has no unsigned long data type that is e.g. used by bitboards. Thus developers have to subtract 18446744073709551616L if the number is bigger then 9223372036854775807L (which mostly means that there is a piece on h8) in order to get the correct bit values.<\/tt>
\n
\nHi Edlich,
\n
\nwelcome to the CPW and thanks for your contribution.
\n
\nI don't get your above quoted statement though - I mean Java long is 64-bit so subtracting 18446744073709551616L, which is 2^64, shouldn't change anything!? Important is to use the unsigned shift right >>> to don't feed in signbits but zeros from left. Did I miss something?
\n
\nCheers,
\nGerd","replyPages":[{"page":0,"digests":[{"id":"5274317","body":"Dear Gerd,
\n
\nthanks for having a sharp eye on my text!
\n
\nWhat I meant is that I subtract in my calculator and then
\nassign the value to java to create a position!
\nI didn't mean a subtraction in java (where you are right).
\n
\nMy example referring to this page:
\nhttp:\/\/en.wikipedia.org\/wiki\/Two_complement<\/a>
\n
\nSo if I have e.g. a 4 bit bitboard (the second graphics on the
\nwikipedia page)
\nand I want to create a bitboard with this position
\n1100 (where the upper bit is set), this is normally a 12. But you
\ncannot set long x = 12 in java. So you have to subtract
\n16 (=2^4) and you get -4 (in my calculator!) which can then be perfectly assigned in java.
\n
\nDo we agree now?
\n
\nThanks and best!
\nStefan Edlich
\n
\nP.S.: If I ever have 2 weeks free I really would like to make
\na pdf book from your fantastic wiki-work with your name on it.
\n
\n
\nMy java test for this:
\n
\n private void testJavaBitboards() {
\n long a = -4548512237353040125L; 1100000011100000011100000011100000011100000011100000011100000011
\n long b = 2025524839466146844L; <\/em> 0001110000011100000111000001110000011100000111000001110000011100
\n long _and = a & b; 0000000000000000000100000001100000011100000011000000010000000000
\n long _or = a | b; <\/em> 1101110011111100011111000011110000011100000111100001111100011111
\n System.out.println("AND=" + _and); 17695735809024
\n System.out.println("OR=" + _or); <\/em> -2523005093622702305
\n }","dateCreated":"1220428248","smartDate":"Sep 3, 2008","userCreated":{"username":"edlich","url":"https:\/\/www.wikispaces.com\/user\/view\/edlich","imageUrl":"https:\/\/www.wikispaces.com\/user\/pic\/1220267569\/edlich-lg.jpg"}},{"id":"5281071","body":"Hi Stefan,
\n
\nI understand now. I find decimals suboptimal for printing bitboards anyway and prefer hex-digits or even printing small boards ;-)
\nI have a small application written in C++ (ugly MFC) to view bitboards pasted via windows clipboard, no matter whether signed decimal or (with 0x prefix) hexadecimal or even fen-strings. It is also an MDI-calculator with all kinds of arithmetical and bitwise logical operations, where I can combine results from several windows, which each has a chess board representation with bitindex written in colored circles for each set bit, and various results, signed decimal, hex, double, utc-seconds and various SIMD vectors of up 8 bytes. There you can multiply diagonals with files and such stuff or simply view bitboards while debugging.
\n
\nI think a small Java-swing (or eclipse plugin?) project for the same purpose would be nice didactic open source application for the CPW, but I guess the windows clipboard (CTEXT) requires some native coding.
\n
\nWe have already some stuff on the two's complement here as well. See
General Setwise Operations<\/a>. You may also have a closer look to Java-Bitscan<\/a>.
\n
\nAn other issue on your text: you mentioned Java 10 times slower that pure C or C++. Is that true for modern 64-bit just in time compilers? I have heard something about 1.5 or 2 slower only, if pre-allocating all dynamic objects (stacks, move-lists) for the search, to keep the garbage collector out of work during.
\n
\nOn making a pdf, why not - but I suggest to wait a little more time, since a lot of more stuff will come. While I have produced the most quantity of changes here, I am not the only contributor, so you should mention the CPW team as author.
\n
\nAre you able to download this chess programming wikispace via
\nManage Space -> Space Exports Backup? (WikiText as well as html)?
\n
\nCheers,
\nGerd","dateCreated":"1220466637","smartDate":"Sep 3, 2008","userCreated":{"username":"GerdIsenberg","url":"https:\/\/www.wikispaces.com\/user\/view\/GerdIsenberg","imageUrl":"https:\/\/www.wikispaces.com\/user\/pic\/1202793136\/GerdIsenberg-lg.jpg"}},{"id":"5292625","body":"Hi Gerd,
\n
\nyou are right. I don't know why I have been stucked to decimal.
\nStrange. And such a tool in Java would also really be cool.
\nI look if my students can write something of this...
\n
\nAnd your second comment is also right with the 64 Bit JIT compilers.
\nI'will change this in the text (although I really have problems
\nto get a 64 Bit Java Compiler for Windows).
\n
\nIf I click on 'Manage Space' I don't see the option
\nSpace Exports Backup :-(
\n
\nSo thanks again for your work and input.
\n
\nBest
\nStefan Edlich
\n
\nP.S. Of course the pdf has time and needs time...","dateCreated":"1220517429","smartDate":"Sep 4, 2008","userCreated":{"username":"edlich","url":"https:\/\/www.wikispaces.com\/user\/view\/edlich","imageUrl":"https:\/\/www.wikispaces.com\/user\/pic\/1220267569\/edlich-lg.jpg"}}],"more":0}]}],"more":false},"comments":[]},"http":{"code":200,"status":"OK"},"redirectUrl":null,"javascript":null,"notices":{"warning":[],"error":[],"info":[],"success":[]}}