Skip to content

Instantly share code, notes, and snippets.

@ytoshima
ytoshima / cpumem.cpp
Created May 23, 2012 09:05
Simple stress program
/*
* A small cpu and memory stress program
* compile: CC cpumem.cpp -o cpumem -lpthread
* or: make LDFLAGS=-lpthread cpumem
*/
#include <pthread.h>
#include <iostream>
#include <vector>
#include <sys/types.h>
#include <assert.h>
@ytoshima
ytoshima / javamem.scala
Last active October 5, 2015 06:48
misc snippets
import collection.JavaConversions._
import java.lang.management._
val MB = (1024*1024).toFloat
def b2mb(bval: Long): Float = bval / MB
def mpoolSum(mp: MemoryPoolMXBean) = "%s: use %.2f comm %.2f max %.2f".format(mp.getName, b2mb(mp.getUsage.getUsed), b2mb(mp.getUsage.getCommitted), b2mb(mp.getUsage.getMax))
def minfo = ManagementFactory.getMemoryPoolMXBeans.filter(_.getType == MemoryType.HEAP).map(mpoolSum).mkString("\n")
@ytoshima
ytoshima / PmapFilter.scala
Created April 24, 2012 10:59
A filter for pmap putout
object PmapFilter {
case class Mr(start: Long, end: Long, desc: String) {
override def toString =
"%08x-%08x %6dk %s".format(start, end, (end-start)/1024, desc)
}
def process(path: String) : String = {
import scala.io.Source
def procMr(current: Mr, prevEnd: Long) = prevEnd match {
case 0 => current.toString
case x if prevEnd == current.start => current.toString
@ytoshima
ytoshima / CoreAmap.scala
Created March 12, 2012 04:40
Prints address map with gap size between segment within a core file
/**
* Prints address map with gap size between segment
* within a core file. This program uses readelf
* command and expects the output is same as the
* readelf on Linux.
*/
object CoreAmap {
def main(args: Array[String]) {
for (a <- args) doAmapCore(a)
}
@ytoshima
ytoshima / gist:1814611
Created February 13, 2012 07:27
TraceMethodHandles sample output
$ ~/local/jdk1.7.0-b147/fastdebug/bin/java -cp classes:lib/asm-4.0.jar name.yt.icache.Pet
D: bsm: type: (Object)void
D: bsm: fallback: MethodHandle(Object)void
D: bsm: fallback: MethodHandle(Object)void
D: fallback: type: (Object)void
D: fallback: type.dropParameterTypes(0,1): ()void
D: fallback: receiverClass: class name.yt.icache.Cat
D: fallback: target: MethodHandle(Cat)void
D: fallback: target after asType: MethodHandle(Object)void
D: fallback: test: MethodHandle(Object)boolean
@ytoshima
ytoshima / JniEx.cpp
Created February 2, 2012 17:41
Simple JNI examples for certain crashes
#include "JniEx.h"
#include <stdlib.h>
void bad_func()
{
int *ip = (int*)0xbffffffe;
*ip = 1;
}
JNIEXPORT void JNICALL Java_JniEx_crash (JNIEnv *env, jclass cls) {
@ytoshima
ytoshima / gist:1381429
Created November 21, 2011 02:22
PrintEscapeAnalysis output example
$ ~/local/jdk1.7.0-b147/fastdebug/bin/java -XX:+Verbose -XX:+PrintEscapeAnalysis -jar ~/local/jdk1.6.0_26/demo/jfc/Java2D/Java2Demo.jar
VM option '+Verbose'
VM option '+PrintEscapeAnalysis'
======== Connection graph for java.util.Properties$LineReader::readLine
519 JavaObject GlobalEscape NSR [[ 578F 589F 623F 624F 452F 468F 469F 602F 606F]] 519 AllocateArray === 503 199 501 8 1 ( 517 506 512 505 10 438 281 22 65 22 384 68 22 1 1 ) [[ 520 521 522 529 530 531 ]] rawptr:NotNull ( int:>=0, java/lang/Object:NotNull *, bool, int ) java.util.Properties$LineReader::readLine @ bci:286 Type:{0:control, 1:abIO, 2:memory, 3:rawptr:BotPTR, 4:return_address, 5:rawptr:NotNull} !jvms: java.util.Properties$LineReader::readLine @ bci:286
LocalVar [[ 519P]] 531 Proj === 519 [[ 532 536 ]] #5 Type:rawptr:NotNull !jvms: java.util.Properties$LineReader::readLine @ bci:286
LocalVar [[ 519P]] 536 CheckCastPP === 533 531 [[ 655 678 655 624 578 578 589 589 624 623 ]] Type:char[i
@ytoshima
ytoshima / c1-result.txt
Created November 18, 2011 16:39
Code comparison between C1 and C2
C1
$ ~/jdk1.7.0-b147/fastdebug/bin/java -XX:CompileOnly=gvnex::doHashSum -XX:+PrintLIR -client gvnex
VM option 'CompileOnly=gvnex::doHashSum'
VM option '+PrintLIR'
CompileOnly: compileonly *gvnex*.doHashSum
LIR:
B1 [0, 0] sux: B0
__id_Instruction___________________________________________
0 label [label:0x939c62c]
@ytoshima
ytoshima / sum.java
Created November 18, 2011 16:02
PrintOptoAssembly output example
// -XX::CompileOnly=sum::doit would narrow down the method to compile, but it
// is not used here.
$ ~/jdk1.7.0-b147/fastdebug/bin/java -XX:+PrintOptoAssembly sum
VM option '+PrintOptoAssembly'
{method}
- klass: {other class}
- this oop: 0x911f8110
- method holder: 'sum'
- constants: 0x911f7e10 constant pool [32] for 'sum' cache=0x911f86b0
@ytoshima
ytoshima / gist:1369697
Created November 16, 2011 09:46
TraceOptoParse output example
static int doit();
flags: ACC_STATIC
Code:
stack=2, locals=2, args_size=0
0: iconst_0
1: istore_0
2: iconst_0
3: istore_1
4: iload_1
5: bipush 100