Skip to content

Instantly share code, notes, and snippets.

View BufferByteToShort.java
package jmh;
import jdk.incubator.vector.ByteVector;
import jdk.incubator.vector.Vector;
import jdk.incubator.vector.VectorMask;
import jdk.incubator.vector.VectorOperators;
import jdk.incubator.vector.VectorShuffle;
import jdk.incubator.vector.VectorSpecies;
import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.BenchmarkMode;
View pr-117.patch
diff --git a/src/hotspot/share/classfile/vmIntrinsics.hpp b/src/hotspot/share/classfile/vmIntrinsics.hpp
index 0035dc20dde..24cfbfb1ac2 100644
--- a/src/hotspot/share/classfile/vmIntrinsics.hpp
+++ b/src/hotspot/share/classfile/vmIntrinsics.hpp
@@ -809,140 +809,278 @@ class methodHandle;
/* Vector API intrinsification support */ \
\
do_intrinsic(_VectorUnaryOp, jdk_internal_vm_vector_VectorSupport, vector_unary_op_name, vector_unary_op_sig, F_S) \
- do_signature(vector_unary_op_sig, "(ILjava/lang/Class;Ljava/lang/Class;Ljava/lang/Class;ILjdk/internal/vm/vector/VectorSupport$Vector;" \
- "Ljdk/internal/vm/vector/VectorSupport$VectorMask;Ljdk/internal/vm/vector/VectorSupport$UnaryOperation;)"\
View TestLoadStoreInts.java
import jdk.incubator.foreign.CLinker;
import jdk.incubator.foreign.MemoryAddress;
import jdk.incubator.foreign.MemorySegment;
import jdk.incubator.foreign.ResourceScope;
import jdk.incubator.vector.IntVector;
import jdk.incubator.vector.VectorSpecies;
import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.BenchmarkMode;
import org.openjdk.jmh.annotations.Fork;
import org.openjdk.jmh.annotations.Measurement;
View TestLoadStoreBytes.java
package jmh;
import jdk.incubator.foreign.CLinker;
import jdk.incubator.foreign.MemoryAccess;
import jdk.incubator.foreign.MemoryAddress;
import jdk.incubator.foreign.MemorySegment;
import jdk.incubator.foreign.ResourceScope;
import jdk.incubator.vector.ByteVector;
import jdk.incubator.vector.IntVector;
import jdk.incubator.vector.VectorSpecies;
@PaulSandoz
PaulSandoz / StringToCharStarStar
Last active Jun 11, 2021
StringToCharStarStar
View StringToCharStarStar
#!/usr/bin/java --source 17 --enable-native-access ALL-UNNAMED --add-modules jdk.incubator.foreign
import jdk.incubator.foreign.*;
import java.util.*;
import java.util.stream.*;
public class StringToCharStarStar {
public static void main(String[] args) {
List<String> strings = List.of(args);
View JMMSample_06_Finals.java
package org.openjdk.jcstress.tests.singletons;
import org.openjdk.jcstress.annotations.Actor;
import org.openjdk.jcstress.annotations.JCStressTest;
import org.openjdk.jcstress.annotations.Outcome;
import org.openjdk.jcstress.annotations.State;
import org.openjdk.jcstress.infra.results.I_Result;
import static org.openjdk.jcstress.annotations.Expect.ACCEPTABLE;
import static org.openjdk.jcstress.annotations.Expect.ACCEPTABLE_INTERESTING;
@PaulSandoz
PaulSandoz / Life.java
Last active Dec 12, 2015
This is an example of Conway's Game of Life using the OpenJDK lambda Stream API. This code works with build from the tip of the lambda repository as of the 1st February 2013. Since the API is a moving this code may not compile with future builds.
View Life.java
/*
* Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
View gist:1334699
(defn render-image [image]
(let [out (ByteArrayOutputStream.)]
(do (ImageIO/write image "png" out) (ByteArrayInputStream. (.toByteArray out)))))
; ":use" needed for compojure.response
(extend-protocol Renderable
BufferedImage
(render [image _]
(-> (ring.util.response/response (render-image image))
(ring.util.response/content-type "image/png"))))
View gist:1333859
(defn- image-mandel-doseq
([[dx dy w h m] limit]
(let [image (BufferedImage. w h BufferedImage/TYPE_INT_RGB)]
(image-mandel-doseq dx dy m image limit)))
([dx dy m ^BufferedImage image limit]
(let [raster (.getRaster image)]
(doseq [[x y rate] m]
(.setPixel raster (int (- x dx)) (int (- y dy)) (ints (rgb (angle rate limit)))))
[dx dy image])))
View gist:1333795
(defn image-mandel
([size a b limit]
(let [[_ _ ms] (mandelbrot-seqs 1 size a b limit)
[_ _ image] (image-mandel-doseq (first ms) limit)]
image))
([n size a b limit]
(let [[w h ms] (mandelbrot-seqs n size a b limit)
image (BufferedImage. w h BufferedImage/TYPE_INT_RGB)
raster (.getRaster image)]
(dorun