This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package safepoint.profiling; | |
import java.util.Random; | |
import java.util.concurrent.TimeUnit; | |
import java.util.concurrent.locks.LockSupport; | |
import java.util.zip.Adler32; | |
import java.util.zip.CRC32; | |
import org.openjdk.jmh.annotations.Benchmark; | |
import org.openjdk.jmh.annotations.BenchmarkMode; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class SafepointProfiling { | |
@Param("1000") | |
int size; | |
byte[] buffer; | |
byte[] dst; | |
boolean result; | |
@Setup | |
public final void setup() { | |
buffer = new byte[size]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
enum { | |
ticks_no_Java_frame = 0, // new thread | |
ticks_no_class_load = -1, // jmethodIds are not available | |
ticks_GC_active = -2, // GC action | |
ticks_unknown_not_Java = -3, // ¯\_(ツ)_/¯ | |
ticks_not_walkable_not_Java = -4, // ¯\_(ツ)_/¯ | |
ticks_unknown_Java = -5, // ¯\_(ツ)_/¯ | |
ticks_not_walkable_Java = -6, // ¯\_(ツ)_/¯ | |
ticks_unknown_state = -7, // ¯\_(ツ)_/¯ | |
ticks_thread_exit = -8, // dying thread |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
typedef struct { | |
jint lineno; // BCI in the source file | |
jmethodID method_id; // method executed in this frame | |
} ASGCT_CallFrame; | |
typedef struct { | |
JNIEnv *env_id //Env where trace was recorded | |
jint num_frames; // number of frames in this trace | |
ASGCT_CallFrame *frames; | |
} ASGCT_CallTrace; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Licensed under the Apache License, Version 2.0 (the "License"); | |
* you may not use this file except in compliance with the License. | |
* You may obtain a copy of the License at | |
* | |
* http://www.apache.org/licenses/LICENSE-2.0 | |
* | |
* Unless required by applicable law or agreed to in writing, software | |
* distributed under the License is distributed on an "AS IS" BASIS, | |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Copyright 2015 dorkbox, llc | |
* | |
* Licensed under the Apache License, Version 2.0 (the "License"); | |
* you may not use this file except in compliance with the License. | |
* You may obtain a copy of the License at | |
* | |
* http://www.apache.org/licenses/LICENSE-2.0 | |
* | |
* Unless required by applicable law or agreed to in writing, software |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static void main(String[] args) throws InterruptedException { | |
SampleLinkedQueue<Integer> q = new SampleLinkedQueue<>(); | |
q.offer(1); | |
System.gc(); // N0, N1 are promoted | |
Thread.sleep(100); | |
q.poll(); // queue is empty, N0 is dead, N1 is alive | |
while(true) { | |
for (int i = 0; i < 4096; i++) { | |
// queue size is kept at 0, but new nodes are created |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class SampleLinkedQueue<E> { | |
static class Node<E> { | |
Node next; | |
E value; | |
} | |
Node<E> head; | |
Node<E> tail; | |
SampleLinkedQueue(){ | |
head = tail = new Node<E>(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Benchmark | |
@CompilerControl(CompilerControl.Mode.DONT_INLINE) | |
public void blameSetResultDeeper() { | |
byte b = 0; | |
for (int i = 0; i < size; i++) { | |
b += buffer[i]; | |
} | |
setResult8(b); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Benchmark | |
public void blameSetResult() { | |
byte b = 0; | |
for (int i = 0; i < size; i++) { | |
b += buffer[i]; | |
} | |
setResult(b); /* LINE 38 */ | |
} | |
private void setResult(byte b) { |