Friday Jul 31, 2015

Presentations on JUG

Presentations on Concurrency GC and Completable Future done in last JUG:

http://files.meetup.com/3189882/CompletableFuture.pdf

http://files.meetup.com/3189882/JUG_Concurrent_GC_Jul2015.pdf

Happy reading !! 

Saturday Jul 25, 2015

Bangalore Java User Group (JUG)- July Meet-up

Today, we had very interesting sessions on Concurrent Garbage Collector and Completable Future by Deepak and Srinivasan.

Deepak, while taking about the Azul Garbage Collector covers: 

- The basics of GC

- How we can proceed for a concurrent GC

- What are the challenges to achieve a concurrency in GC

Srinivasan while talking about the Completable Future covers: 

- How the new Completable Future of JDK 8 is better than the old calls

- How the real life applications like Banking, Online booking systems can use this feature.

- What were the old bottleneck which got addressed.

If you are also interesting in joining Bangalore Java User Group, follow us on:

Our meetup page - http://www.meetup.com/BangaloreOpenJUG/

Our Facebook page - https://www.facebook.com/groups/1018617618156273/

 Soon, I will provide the links for the presentation. 

Monday Jul 13, 2015

A fast overview of Just-In-Time(JIT) Compiler

JIT comes in these flavors:
 C1 (Client compiler) -client option
 C2 (Server compiler)-server option
 -XX:+TieredCompilation - Better decision of compilers.

Common Optimizations done by Just-In-Time (JIT) Compiler do:

 1. Eliminate dead codes and Expression optimization.

 int someCalculation(int x1, int x2, int x3) {
         int res1 = x1+x2;
         int res2 = x1-x2;
         int res3 = x1+x3;
         return (res1+res2)/2; 
 }

will be converted to

int someCalculation(int x1, int x2, int x3) {
	return x1; 
} 

 2. Inline Method

- Substitute body of the method (<35 bytes of JVM bytecode) - This provides the best optimization by JIT - A better inline that C++ 

For Example: 

int compute(int var) { int result; if(var > 5) { result = computeFurther(var); } else { result = 100; } return result; } 

If you call myVal = compute(3); it will get converted into myVal = 100;

 

3. Caching Technique:

Point findMid(Point p1, Point p2) { Point p; p.x = (p1.x + p2.x)/2; p.y = (p1.y + p2.y)/2; return p;

p1.x, p2.x -> It can convert into temp1, temp2 and can be cached.

 

4. Monomorphic dispatch:

public class Birds { private String color; public String getColor() { return color; } } myColor = birds.getColor(); 

If there is no other override of this method, it will convert into

public class Birds { String color; }

mycolor = birds.color; 

 

5. Null Checks Removal:

x = point.x; y = point.y; At JVM it is equivalents to: if(point==null) throw new NullPointerException(); else { x = point.x; y = point.y; }  

But if the code will not throw NullPointer for more than threshold reference, it will remove the if check.

 

6. Threading Optimizations:

- Eliminate locks if monitor is not reachable from other threads - Join adjacent synchronized blocks on the same object

7. Loop Optimizations: 

- Combining loops – Two loops can be combined if taking equivalent time. - Inversion loops – Change while into do-while. (why, just give a javap -c) - Tiling loops – Re-organize loop so that it will fix in cache. 

 

VM Args:

Xint – Interpreter mode Xcomp – Compiled mode Xmixed – Interpreter + Compiler -server → C2 compiler -client → C1 compiler -XX:+TieredCompilation → C1 + C2 (used by 32/64 bit mode) 

 

Logging Options:

-XX:+UnlockDiagnosticVMOptions -XX:+LogCompilation -XX:LogFile=<path to file> -XX:MaxInlineSize=<size> -XX:FreqInlineSize=<size> 

(For more see my last blog)

 

 

Tuesday Jul 07, 2015

VM Options for C1 and C2

Many Java Developers often ask what are the flag options available for C1 and C2 Compilers or what are the flag options available for JIT compilers. Though most of the time our slides will cover some of the important VM options (-XX) but certainly we can't  provide the list of complete option in slides. This is actually quite a trivial job.

Here it goes:

1. Complete VM global flag option (redirecting it to out file):

java -XX:+UnlockDiagnosticVMOptions -XX:+PrintFlagsFinal > out

wc -l < out

764  // Total available options, did on jdk7

2. If you will check without  UnlockDiagnosticVMOptions, the no.s will be bit less.

java  -XX:+PrintFlagsFinal > out

wc -l < out

672 

2. This document comes with the beautiful option of where it is been used like Product, C2 diagnostic, C1 Product and many more. So, just grep the out file with "C2" and see what options are available for you on C2 Compiler and which options are product options and which are diagnostic or logging options.

 cat out | grep "C2" 

A list will come something like:

     intx AliasLevel                                = 3               {C2 product}

     bool AlignVector                               = true            {C2 product}

     intx AutoBoxCacheMax                           = 128             {C2 product}

     bool BlockLayoutByFrequency                    = true            {C2 product}

     intx BlockLayoutMinDiamondPercentage           = 20              {C2 product}

     bool BlockLayoutRotateLoops                    = true            {C2 product}

     bool BranchOnRegister                          = false           {C2 product}

     intx ConditionalMoveLimit                      = 3               {C2 pd product}

     bool DebugInlinedCalls                         = true            {C2 diagnostic}

ccstrlist DisableIntrinsic                          =                 {C2 diagnostic}

     bool DoEscapeAnalysis                          = true            {C2 product}

     intx DominatorSearchLimit                      = 1000            {C2 diagnostic}

     intx EliminateAllocationArraySizeLimit         = 64              {C2 product}

     bool EliminateAllocations                      = true            {C2 product}

     bool EliminateAutoBox                          = false           {C2 diagnostic}

     bool EliminateLocks                            = true            {C2 product}

     bool EliminateNestedLocks                      = true            {C2 product}

     bool IncrementalInline                         = true            {C2 product}

     bool InsertMemBarAfterArraycopy                = true            {C2 product}

     intx InteriorEntryAlignment                    = 16              {C2 pd product}

     intx LiveNodeCountInliningCutoff               = 20000           {C2 product}

 3. Running the same option for C1.

cat out | grep "C1" 

We can see:

     bool C1OptimizeVirtualCallProfiling            = true            {C1 product}

     bool C1ProfileBranches                         = true            {C1 product}

     bool C1ProfileCalls                            = true            {C1 product}

     bool C1ProfileCheckcasts                       = true            {C1 product}

     bool C1ProfileInlinedCalls                     = true            {C1 product}

     bool C1ProfileVirtualCalls                     = true            {C1 product}

     bool C1UpdateMethodData                        = true            {C1 product}

     intx CompilationRepeat                         = 0               {C1 product}

     bool LIRFillDelaySlots                         = false           {C1 pd product}

     intx SafepointPollOffset                       = 256             {C1 pd product}

     bool TimeLinearScan                            = false           {C1 product}

     intx ValueMapInitialSize                       = 11              {C1 product}

     intx ValueMapMaxLoopSize                       = 8               {C1 product}

 Enjoy JIT'ing.

Saturday Jul 04, 2015

20 Years of Java In India

20 years of Java has been celebrated across the globe. Here in India Center (IDC), we had a small celebration. Look at our new "Duke" Shirts :). We have Bernard joining for the celebration (search where !!).


Wednesday Jul 01, 2015

Bangalore Java User Group (JUG)- Meeting in July

Talks in List: 

Concurrent Garbage Collection - Harish Babu -  60 mins

Completable Future - Srinivasan Raghavan -  45 mins

Java 8 new Javascript engine call Nashorn - Shekhar Gupta   45 mins

Friday Mar 26, 2010

Tech Days 2010 @ Hyderabad

2010 Sun Tech days over. Nice time at presentation and in train too. Nothing more to write. James was good. 

Presentation here: 

 G1 presentation  and mixing Lightweight/Heavyweight components.

Tuesday Dec 22, 2009

LiveConnect improvement in JDK6

JDK6 has done lot of changes in LiveConnect. LiveConnect is a feature in the browser for communication between Java Applet and JavaScript. With the new Plugin2, most of the work has been left on browser to do. Initially it was Java which do a good amount of work. So, now the Java Plug-in will operate like any other scriptable Plug-in. ..............
[Read More]

Tuesday Dec 15, 2009

Lightweight and Heavyweight components - Mess it !

So, if you are a Swing Developer, you have heard many stories where someone messed Lightweight component with Heavyweight component. In one line " A heavyweight component is one that is associated with its own  native screen resource (commonly known as a peer). A lightweight component is one that "borrows" the screen resource of an ancestor  (which means it has no native resource of its own -- so it's "lighter")."

 Now many times you have heard "Don't mix lightweight and heavyweight". What will happen ? Alright, here is a small code : ............

[Read More]

Wednesday Nov 25, 2009

Sorting and OpenJDK

If you are looking for sorting algorithms and if you use some sorting algorithm in your code/application/big application, then have a look here. First of all sorting/searching is a classic thing. It take more than 70 percent of your application time.People/Developer/Mathematician do a lot of work on optimizing this work to get Best, best out of best.

Early days, JDK used to use QuickSort which is one of the best sorting algorithm and go for a complexity of O(nlogn). But mind it, QuickSort is a recursive algorithm and consume space. Whereas some of the algorithm which has the complexity like O(n\^2) go for less complex in terms of memory. These days our platform varies from small mobile device to a terabyte storage machine............

[Read More]

Monday Aug 24, 2009

Debugging basics and some link - Java

Some simple debugging tools related to Java. These are for those who are new to Java.

1. Application is crashing : Most miserable one. Get your log file, try to analysis log. How to write log file, use Java Logger API.  Java Logger had been introduced in JDK 1.4.2. The most awesome feature of  Logger API is that you can use it in production without much overhead. The overhead is controlled by something called level in API. Level goes from FINEST to SEVERE. You can refer to O'Relly Book "Java, In a NutShell". I guess. ...........
[Read More]

Wednesday Aug 12, 2009

Netbeans Java Presentation

Small presentation(actually very small) on Netbeans and Java. Mostly covers the features, netbeans provide for Java SE. Like Profiling, Debugging..

http://blogs.sun.com/vaibhav/resource/BasicOfNetbeans_Java.pdf



Thursday Jun 18, 2009

Browser + Drag + Feature + JavaFX + Profile + Many more :)

Final destination for us is death and final destination of a JavaFX application is Browser. So, we should know what all things we can do with an application, JavaFX application, in browser.

Here are some :

1. Understand when our code will run on browser and when on Desktop/Mobile and optimize the code. Here is a small one :

package appletshow;

import javafx.scene.\*;
import javafx.scene.input.MouseEvent;
import javafx.scene.paint.\*;
import javafx.scene.shape.\*;
import javafx.scene.text.\*;
import javafx.stage.\*;

/\*\*
 \* @author Vaibhav Choudhary
 \*/

var textContent = "Hello JavaFX in applet World";
var subtext = "Drag me out for this example(Alt->Drag)";
var vis = false;
var s: Stage = Stage {
    title: "Applet Show"
    width : 600 height : 200
    style: StageStyle.TRANSPARENT
    scene : Scene {
            fill: Color.BLACK
            content: [
                Text { content: textContent
                       x: 25 y:35 fill: Color.WHITE
                       font: Font{size: 24}
                }
                Text { content:  subtext
                       x: 25 y:55 fill: Color.WHITE
                       font: Font{size: 14}
                }

                Rectangle { x: 560 y: 10 width: 20 height: 20
                            arcHeight:5
                            arcWidth: 5
                            stroke:Color.GRAY
                            strokeWidth: 2
                            fill: Color.TRANSPARENT
                            visible: bind ("{__PROFILE__}" != "browser")
                            onMouseClicked: function(e: MouseEvent): Void {
                                s.close();
                            }
                }
                Text {
                    fill: Color.WHITE
                    visible: bind ("{__PROFILE__}" != "browser")
                    font : Font {
                        name:"Arial Bold"
                        size: 14
                    }
                    x: 567, y: 25
                    content: "x"
                }
                ,
            ]
    }
}

Close button will be visible only in browser not in desktop/mobile. So, this is logical, close button should not be in Browser.

2. Remeber, we have draggable feature and things can change from applet inside the browser and when it has been dragged out :).

Now, I want again that when I dragged my applet out of the browser, I get a close button which is logical again, because a dragged application is like a desktop application. So, here we go :)


package appletshow2;

import javafx.scene.\*;
import javafx.scene.input.MouseEvent;
import javafx.scene.paint.\*;
import javafx.scene.shape.\*;
import javafx.scene.text.\*;
import javafx.stage.\*;

var textContent = "Hello JavaFX in applet World";
var subtext = "Drag me out for this example(Alt->Drag)";
var vis = false;
var s: Stage = Stage {
    title: "Applet Show"
    width : 600 height : 200
    style: StageStyle.TRANSPARENT
    scene : Scene {
            fill: Color.BLACK
            content: [
                Text { content: textContent
                       x: 25 y:35 fill: Color.WHITE
                       font: Font{size: 24}
                }
                Text { content:  subtext
                       x: 25 y:55 fill: Color.WHITE
                       font: Font{size: 14}
                }

                Rectangle { x: 560 y: 10 width: 20 height: 20
                            arcHeight:5
                            arcWidth: 5
                            stroke:Color.GRAY
                            strokeWidth: 2
                            fill: Color.TRANSPARENT

                    visible: bind vis
                            onMouseClicked: function(e: MouseEvent): Void {
                                s.close();
                            }
                }
                Text {
                    fill: Color.WHITE
                    visible: bind vis
                    font : Font {
                        name:"Arial Bold"
                        size: 14
                    }
                    x: 567, y: 25
                    content: "x"
                }
                ,
            ]
    }
    extensions: [
        AppletStageExtension {
            onDragStarted: function() {
                vis = true;
            }
            onAppletRestored: function() {
                vis  = false;
            }
            useDefaultClose: false
        }
    ]
}

Points to remember : a. useDefaultClose : false, it will vanish the default close button else it will be a mess, seeing too many close buttons. b. AppletStageExtension has lot of other features, please check the API. c. Close button should vanish once it goes back into the browser. 

3. Ah, now most important about dragging feature. I don't want to drag applet with Alt-> Drag feature, I want it should be draggable in simple style like we do with other application, NO COMPLICATION. Use this :)



package shoulddrag;

import javafx.lang.FX;
import javafx.scene.input.MouseEvent;
import javafx.scene.paint.Color;
import javafx.scene.Scene;
import javafx.scene.shape.Rectangle;
import javafx.scene.text.Font;
import javafx.scene.text.Text;
import javafx.stage.AppletStageExtension;
import javafx.stage.Stage;
import javafx.stage.StageStyle;
import javafx.scene.paint.LinearGradient;
import javafx.scene.paint.Stop;

/\*\*
 \* @author Vaibhav Choudhary
 \*/

var isApplet = "true".equals
(FX.getArgument("isApplet") as String);
var inBrowser = isApplet;
var dragRect: Rectangle;
var draggable = AppletStageExtension.appletDragSupported;
dragRect = Rectangle {
    x: 0
    y: 0
    width: 240
    height: 40
    opacity: 0.5
    fill: LinearGradient {
        startX: 0.0
        startY: 0.0
        endX: 0.0
        endY: 1.0
        stops: [
            Stop {
                color: Color.BLACK
                offset: 0.0
            },
            Stop {
                color: Color.WHITE
                offset: 0.3
            },
            Stop {
                color: Color.BLACK
                offset: 1.0
            },

        ]
    }
    onMouseDragged: function(e:MouseEvent):Void {
        print(inBrowser);
        stage.x += e.dragX;
        stage.y += e.dragY;
    }
};
var dragTextVisible = bind draggable and dragRect.hover;
var can_drag_me_text: Text = Text {
    content: "You can drag me !"
    fill: Color.BLACK
    font: Font {
        size: 12
        embolden: true
        name: "Arial Bold"
    }

    opacity: 1.0
    visible: bind dragTextVisible
    y: 20
    x: 15
};
var stage = Stage {
    title: "Should Drag"
    width: 250
    height: 280
    style: StageStyle.TRANSPARENT
    scene: Scene {
        content: [
            dragRect,
            Rectangle {
                x: 0,
                y: 40
                width: 240,
                height: 290
                fill: Color.BLACK
            },
            can_drag_me_text
        ]
    }
    extensions: [
        AppletStageExtension {
            shouldDragStart: function(e): Boolean {
                return e.primaryButtonDown and dragRect.hover;
            }
            onDragStarted: function(): Void {
                inBrowser = false;
            }
            onAppletRestored: function(): Void {
                inBrowser = true;
            }
            useDefaultClose: true
        }
    ]
}

Some complication are in code, but be relaxed and see, too easy, RIGHT ? Alright ! What more we can add here...

Please let me know if there is any issue with any of the code. Thanks !

Wednesday Mar 25, 2009

New Articles on JavaFX.com

So, finally we kicked off the new Article section on javafx.com. Go to the "Explore section". Hit "Overview", see "Overview and New Articles". We have 3 articles there right now.

1. Making a Point-Line Graph.

2. Write an app on Mobile.

3. Improve startup time for FX Apps.

and many more to come.

I don't know if there is a link where we can request for articles but you can definetely leave a comment here, we will take care of it :).


Monday Mar 23, 2009

Mega and Micro Challenges on the way ...FX'ing

Some great news for JavaFX developers. 

1.  JavaFX Coding Challenge starting from today, 23rd March.

For more please visit :  http://javafx.com/challenge/

Some eye catching stuff : Prizes, 25000, 10000, 5000, 1500, 100 $. Have a look !  

2. Another Challenge Josh has announced today on jfxstudio.org. Winners of JavaFX Application developer will get new upcoming book of JavaFX. Hava a look here as well.

So, its like writing one application and chance for getting lot of prizes :).

All the best to the competitors.

About

Vaibhav Hi, I am Vaibhav Choudhary working in Oracle with JDK team. This blog is all about simple concept of Java, JVM and JavaFX.

Search

Categories
Archives
« August 2015
SunMonTueWedThuFriSat
      
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
     
Today