background preloader

Java

Facebook Twitter

Java/C# Tagging Via Generics. Domain Driven Design makes screwing up code much harder and makes IDEs very much more helpful; but C# and Java have issues with it.

Java/C# Tagging Via Generics

The approach I outline here fixes them via generic type tagging. [Note: I see no reason this will not work in C# but for the sake of time I am only implementing this in Java here.] This idea is part of the general 'function/object sweet spot' research project. I am using the sort of type inference tricks we more normally see in functional systems like Scala, F# or C++ templates to make Java coding much more type safe and declarative. The Challenge: All the object representations of primitive types are final (sealed). Public String assembleFullName(String firstName,String secondName); We do not want this because it is far to easy to send the wrong data to the method. Public fullName assembleFullName(FirstName firstName, SecondName secondName); But, we cannot subclass String. Tagging: JSR292 For Unions - The Reddit Conversation. Comparing Java 7 Garbage Collectors Under Extreme Load. To explain, a realtime system must have a deterministic time to complete a task.

Comparing Java 7 Garbage Collectors Under Extreme Load

"Stop the world" garbage collectors break this model. I have an idea how to allow a mix of deterministic/realtime and normal JVM execution without having to go over to the full Java Real Time VM. JNI Driving Single Threaded Libraries Using Multiple Threads In 1 Process! This seems too simple.

JNI Driving Single Threaded Libraries Using Multiple Threads In 1 Process!

If ANYONE can find some where I have gone wrong, please let me know. If I am correct, this solves one of the biggest issues I have seen in several recent big JNI integration projects. With this single threaded native libraries can be driven from multiple JVM threads using JNI all in process. Multi-tenancy yields huge performance benefits in modern computing. This is ever more the case as multi-core architectures come to dominate computing.

The 'best' solutions are to re-write the old code to be thread safe or even port it to a more modern language (or dialect). I believe there is a much simpler, lower cost and more powerful solution for a dominant subset of these challenges. I am presenting the simplest possible example here. Dynamically loaded libraries have encapsulated memory spaces unless symbols are exported. More Garbage Collector Carnage. In A Previous Post I demonstrated some issues with the G1 collector in the JVM 1.7 system.

More Garbage Collector Carnage

Here I peek a little further into the issue. On of the biggest failings with the original post was that I did not consider any or the tuning flags for the garbage collector. I also id not include the effects of having more memory. The 3 Pillars Of JNI. JNI can be tamed.

The 3 Pillars Of JNI

Here I introduce the three pillars. Building all JNI coding on these is the key to successful, pain free, reliable code. JNI, the technology for interacting between JVM languages and native code, has gained something of a harsh reputation. I have found that a large part of this is because of the paradigm of coding people are using with JNI is dysfunctional, not JNI its self.

This podcast introduces the 3 pillars approach. Performance and safety. Synchronizing a single value between threads is the corner stone of a lot of high performance thread safe algorithms; but which is the best way to do it?

Performance and safety

The super naive programmer might just define a shared int field. This does not work because the JVM makes no guarantees at all about updates to such a field from different threads. A slightly more experienced developer might realise that if a field is marked 'volatile' then the JVM is guaranteed to synchronise its value between all threads before any read or write. Oracle Monetizes Java. Hmmm - could be ominous or it could be a good thing.

Oracle Monetizes Java

It definitely is a big change. Oracle is gearing up to put pay for features into the JVM. It has been a bit ridiculous to be honest; how and why Sun just gave away Java and the JVM was strange when it started and it is no shock to me that this period of history is coming to an end. Is Curry The Saviour Of Java? Java really does not need saving - it is in rude health.

Is Curry The Saviour Of Java?

Nevertheless, a lot of the original programming paradigm for Java is starting to feel very clunky and laborious. Can a change in style alone help? I am not talking about a full blown implementation of Currying which mimics the behaviour of Haskell. What is quite easy in Java is to make the return type of a method have methods on it which perform the next step in the computation chain.

Big Decimal Internal DSL For Java. I suggested that Currying could be the saviour of Java.

Big Decimal Internal DSL For Java

One area in which Java is very weak is exact decimal calculation. Here I present an internal dsl approach for helping overcome this weakness. BigDecimal does everything we need but it is clunky to work with using the traditional Java programming paradigm. As I demonstrated in this post some time ago, the traditional approach is to create new BigDecimal objects using the new operator and then perform calculations with them using the virtual methods on the BigDecimal object.

BigDecimal is a immutable type which has methods for all the major mathematical operations each of which produce a new BigDecimal. Currying Paradigm: In this approach we only use methods as functions which take zero or one argument. Quant Calculations With Distributed Excel - 1. Intro: There are many calculations which do not lend themselves to ab-initio computation.

Quant Calculations With Distributed Excel - 1

In other words, working out an algebraic solution to the question represented by the calculation is either impossible or impractical. The reason people often think this is a small set of calculations is that we try and avoid them; in reality, the set of such calculations is larger than the set of calculations which lend themselves to ab-inito resolution. It would appear that the drive for ab-initio solutions often leads calculations in the statistical and probabilistic space to be performed with unsupportable assumptions.

Java Is Not Going Anywhere Soon! Despite rumours to about the imminent demise of Java, it will be with us and growing as a technology for quite some time to come: Here are my five reasons Java is not going anywhere soon (in HD if you watch on Youtube). Also, at the bottom of this post are some interesting job stats which help drive the point home. Tackling Legacy Languages With JVM Invokedynamic. Invokedynamic can be considered for dynamic languages like Magik or Ruby. But - there are very good reasons for moving legacy code like C or COBOL onto managed evironments; invokedyamic might just be the key to making these run super fast (potentially faster than native). Invokedynamic in JRuby: Constant Lookup.

This is the first of a set (not a series...there's no particular order) of articles I'll write on how JRuby is using invokedynamic. Hopefully they will show Rubyists how drastically invokedynamic is going to improve JRuby, and show other JVM language folks how to use invokedynamic effectively. Hello friends! I figured it's about time for me to start writing a bit on how JRuby is actually using invokedynamic. As of today, JRuby utilizes invokedynamic far more than any other mainstream JVM language. We have worked very closely with the JSR leads and the OpenJDK developers to make sure invokedynamic runs well. VM Spec. Java SE 9 The Java Language Specification, Java SE 9 Edition. Contents. JNI Enhancements in the Java 2 SDK. Download.oracle.com/javase/1.3/docs/guide/jni/spec/jniTOC.doc.html. Download.oracle.com/javase/6/docs/technotes/guides/jni/spec/functions.html#nio_support.

JNI Functions Chapter 4 This chapter serves as the reference section for the JNI functions. It provides a complete listing of all the JNI functions. It also presents the exact layout of the JNI function table. Note the use of the term “must” to describe restrictions on JNI programmers. A portion of this chapter is adapted from Netscape’s JRI documentation. The reference material groups functions by their usage. Interface Function Table. JDK 6 I/O-related APIs & Developer Guides. Enhancements in Java I/O. Understanding JVM Performance - It is Fast - Very Fast! JVM code can be just as fast as the equivalent native code. Deep Dive Java Performance And Escape Analysis. Escape Analysis, Values Types And JVM Optimisation. I was going to post the code for my high speed JVM based transaction demo. But it has been a funny kind of day and so that will have to wait. Tuning The JVM For Unusual Uses - Have Some Tricks Under Your Hat.

Knowing a little more about the guts of the JVM can make a huge difference, especially if you are coding off the beaten track.Speed counts! C#-VSLP vs J-VSPL, Interesting Stuff Shown Up. VSPL - So simple an amoeba can understand it! A Report Of VSPL From C# To Java Gives Some Surprising Results. JDK: DirectByteBuffers Seem V.Slow On Sun JDK. Java On Ubuntu 64 Massively Faster Than Vista 32. Extreme JNI Performance. For the record - my life with Java :) Java Type 'Erasure': What A Pile Of Bollocks. COBOL vs JAVA for financial calculations.

A High speed variable look up data structure for Java based dynamic languages. A canyon size flaw in at the heart of C# and Java. Java Inner Classes - Under The Hood. Java, JVM, JNI and Signal Handling Explained In Simple Terms. Performing DynamicInvoke From Java - A Step By Step Journey. JVM/Java: Comparing InvokeDynamic Performance To Invokestatic. Develop JVM 1.7 / InvokeDynamic In Eclipse - Step by step guide. 026-Podcast: JVM And The Dynamic Revolution. JVM/Dynamic Languages: Very Fast Return Path Trick. Overview (Java Platform SE 7 ) Lang.invoke (Java Platform SE 7 ) MethodHandles.Lookup (Java Platform SE 7 ) Java™ Platform Overview. Java Platform Standard Edition 7 Documentation. Java SE 7 Virtual Machine (VM)-related APIs & Developer Guides. Java ™ HotSpot Virtual Machine Performance Enhancements. VisualVM.