Skip to content

Instantly share code, notes, and snippets.

View chriswhocodes's full-sized avatar

Chris Newland chriswhocodes

View GitHub Profile
@chriswhocodes
chriswhocodes / gist:6839214
Created October 5, 2013 10:23
Normalise a double in a range and scale to a dimension (with optional invert). Useful for chart scaling.
public static double normalise(double value, double min, double max, double size, boolean invert)
{
double range = max - min;
double result = 0;
if (range != 0)
{
result = (value - min) / range;
}
@chriswhocodes
chriswhocodes / JavaCard.java
Last active December 25, 2015 16:59
Andrew Kensler's business card raytracer converted to Java
package com.chrisnewland.raytrace;
import java.io.FileOutputStream;
/*
* Standing on the shoulders of giants.
* I didn't invent this raytracer, just converted it from C to Java with the help of this web page by Fabien Sanglard:
* http://fabiensanglard.net/rayTracing_back_of_business_card/index.php
* The original code is by Andrew Kensler. Comments copied from Fabien Sanglard's notes.
*/
@chriswhocodes
chriswhocodes / TestFileChooser.java
Created January 24, 2014 15:46
JavaFX FileChooser.ExtensionFilter *.* not working on OSX
import java.io.File;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.layout.BorderPane;
import javafx.stage.FileChooser;
import javafx.stage.Stage;
public class TestFileChooser extends Application
{
@chriswhocodes
chriswhocodes / gist:60774526fd00dcf2891a
Last active August 29, 2015 14:03
buildIR nodes from SandboxTest with -XX:+TieredCompilation
<task_queued osr_bci="12" method="SandboxTest main ([Ljava/lang/String;)V" compile_kind="osr" level="3" bytes="56" count="1" backedge_count="69632" stamp="0.199" comment="tiered" hot_count="69632" compile_id="34" iicount="1"/>
<nmethod stub_offset="2448" dependencies_offset="3672" compileMillis="10" address="0x00000001048dda50" method="SandboxTest main ([Ljava/lang/String;)V" level="3" count="1" backedge_count="375551" stamp="0.209" nul_chk_table_offset="3680" scopes_data_offset="2736" iicount="1" oops_offset="2680" entry="0x00000001048ddc40" size="3728" scopes_pcs_offset="3064" compile_kind="osr" insts_offset="496" bytes="56" relocation_offset="288" compile_id="34" compiler="C1"/>
<task_queued method="SandboxTest main ([Ljava/lang/String;)V" level="3" bytes="56" count="1" backedge_count="376371" stamp="0.209" comment="tiered" hot_count="1" compile_id="35" iicount="1"/>
<nmethod inlined_bytes="26" backedge_count="1000000" stamp="0.217" scopes_data_offset="2608" osr_bci="12" scopes_pcs_offset="2912" insts_offs
@chriswhocodes
chriswhocodes / gist:ad26dbbb5fc4703a8489
Created June 27, 2014 20:50
buildIR nodes from SandboxTest with -XX:-TieredCompilation
<task_queued osr_bci="12" method="SandboxTest main ([Ljava/lang/String;)V" compile_kind="osr" bytes="56" count="1" backedge_count="14563" stamp="0.086" comment="backedge_count" hot_count="14563" compile_id="5" iicount="1"/>
<nmethod stub_offset="560" dependencies_offset="848" compileMillis="2" inlined_bytes="20" address="0x0000000106466650" method="SandboxTest main ([Ljava/lang/String;)V" count="10000" backedge_count="5681" stamp="0.088" nmsize="248" scopes_data_offset="632" iicount="1" oops_offset="584" entry="0x00000001064667a0" osr_bci="12" size="864" scopes_pcs_offset="688" compile_kind="osr" insts_offset="336" bytes="56" success="1" relocation_offset="288" compile_id="5" compiler="C2"/>
<task osr_bci="12" method="SandboxTest main ([Ljava/lang/String;)V" compile_kind="osr" bytes="56" count="10000" backedge_count="5336" stamp="0.086" compile_id="5" iicount="1">
<phase nodes="3" name="parse" stamp="0.086" live="3">
<type name="void" id="680"/>
<klass name="[Ljava/lang/String;" flags="1041" id="777
@chriswhocodes
chriswhocodes / SandboxTest.java
Created June 27, 2014 20:53
File used to test TieredCompilation output
public class SandboxTest
{
public int a(int x)
{
return 1 + b(x);
}
public int b(int x)
{
return 1 + c(x);
#!/bin/sh
#================================================================================
# This script fetches and builds the latest OpenJDK9 and OpenJFX (currently 8u40)
# and installs OpenJFX into the OpenJDK j2sdk image.
#
# It requires an existing 1.8 JDK installation to bootstrap the OpenJDK build
# (I used Oracle jdk1.8.0_20).
#
# Tested on Debian x86_64 (Squeeze and Wheezy)
processor : 0
vendor_id : GenuineIntel
cpu family : 6
model : 37
model name : Intel(R) Core(TM) i5 CPU 660 @ 3.33GHz
stepping : 5
microcode : 0x2
cpu MHz : 1199.000
cache size : 4096 KB
physical id : 0
@chriswhocodes
chriswhocodes / jfxrt.jar.csv
Created November 3, 2014 22:02
List of methods from jdk1.8.0_25 jfxrt.jar that are above the 325 byte method bytecode limit for "hot" method inlining
We can make this file beautiful and searchable if this error is corrected: Unclosed quoted field in line 8.
/home/chris/jdk1.8.0_25/jre/lib/ext/jfxrt.jar:
"com.sun.deploy.uitoolkit.impl.fx.FXPreloader$FXDispatcher","public java.lang.Boolean call()",479
"com.sun.deploy.uitoolkit.impl.fx.FXProgressBarSkin","public com.sun.deploy.uitoolkit.impl.fx.FXProgressBarSkin(javafx.scene.control.ProgressBar)",463
"com.sun.deploy.uitoolkit.impl.fx.FXProgressBarSkin","protected void layoutChildren(double,double,double,double)",388
"com.sun.deploy.uitoolkit.impl.fx.ui.CertificateDialog","private static javafx.scene.Node getComponents(javafx.stage.Stage,java.security.cert.Certificate[],int,int)",362
"com.sun.deploy.uitoolkit.impl.fx.ui.CertificateDialog","private static void showCertificateInfo(java.security.cert.X509Certificate,javafx.scene.control.TableView,javafx.scene.control.TextArea)",397
"com.sun.deploy.uitoolkit.impl.fx.ui.DialogTemplate","private javafx.scene.layout.BorderPane createSSVTopPanel(java.lang.String,java.lang.String,java.lang.String)",383
"com.sun.deploy.uitoolkit.impl.fx.ui.DialogTemplate","private javafx.scen
package org.sample;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.concurrent.TimeUnit;
import javax.script.Invocable;
import javax.script.ScriptEngineManager;
import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.BenchmarkMode;