Skip to content

Commit 1aaee99

Browse files
author
Jaroslav Tulach
committed
[GR-36869] Using JEP-413 Javadoc tags to show snippets in graal/sdk project.
PullRequest: graal/11127
2 parents 1bc5eca + ed15ac4 commit 1aaee99

File tree

5 files changed

+32
-29
lines changed

5 files changed

+32
-29
lines changed

sdk/mx.sdk/suite.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
# SOFTWARE.
4040
#
4141
suite = {
42-
"mxversion" : "5.317.17",
42+
"mxversion" : "5.318.0",
4343
"name" : "sdk",
4444
"version" : "22.1.0",
4545
"release" : False,

sdk/src/org.graalvm.nativeimage.test/src/org/graalvm/nativeimage/ImageSingletonsTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2019, 2022, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* The Universal Permissive License (UPL), Version 1.0
@@ -63,11 +63,11 @@ public void lookupCannotBeUsedInRegularJDK() throws Exception {
6363

6464
@Test
6565
public void checkAndUseWorksOnRegularJDK() throws Exception {
66-
// BEGIN: org.graalvm.nativeimage.ImageSingletonsTest
66+
// @start region="ImageSingletonsTest"
6767
if (ImageSingletons.contains(MyService.class)) {
6868
MyService myService = ImageSingletons.lookup(MyService.class);
6969
myService.useMyService();
7070
}
71-
// END: org.graalvm.nativeimage.ImageSingletonsTest
71+
// @end region="ImageSingletonsTest"
7272
}
7373
}

sdk/src/org.graalvm.nativeimage/src/org/graalvm/nativeimage/ImageSingletons.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2012, 2019, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2012, 2022, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* The Universal Permissive License (UPL), Version 1.0
@@ -86,20 +86,22 @@ public static <T> T lookup(Class<T> key) {
8686
return ImageSingletonsSupport.get().lookup(key);
8787
}
8888

89+
// @formatter:off
8990
/**
9091
* Checks if a singleton is in the registry. The key must be a compile time constant, so that
9192
* the call to this method can be replaced with the constant {@code true} or {@code false}.
9293
* <p>
9394
* The method returns {@code false} since 19.3.0 when not used in the context of a native image.
9495
* As such it is safe to write:
9596
*
96-
* {@codesnippet org.graalvm.nativeimage.ImageSingletonsTest}
97+
* {@snippet file="org/graalvm/nativeimage/ImageSingletonsTest.java" region="ImageSingletonsTest"}
9798
*
9899
* and let such code run fine in the context of {@link ImageInfo#inImageCode() native image} as
99100
* well as outside of it.
100101
*
101102
* @since 19.0
102103
*/
104+
// @formatter:on
103105
public static boolean contains(Class<?> key) {
104106
if (!ImageInfo.inImageCode()) {
105107
return false;

sdk/src/org.graalvm.nativeimage/src/org/graalvm/nativeimage/StackValue.java

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2013, 2021, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2013, 2022, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* The Universal Permissive License (UPL), Version 1.0
@@ -59,12 +59,13 @@ private StackValue() {
5959
/**
6060
* Reserves a block of memory for given {@link CStruct} class in the stack frame of the method
6161
* that calls this intrinsic. This is a convenience method for calls to:
62-
* {@codesnippet org.graalvm.nativeimage.StackValueSnippets#withSizeOf}
62+
* {@snippet file="org/graalvm/nativeimage/StackValue.java" region="withSizeOf"}
6363
*
6464
* It can be used to allocate a structure on the stack. The following example allocates a
6565
* {@code ComplexValue} and then sends it as a regular parameter to another function to compute
6666
* absolute value of the number:
67-
* {@codesnippet org.graalvm.nativeimage.StackValueSnippets#ninePlusSixteenSqrt}
67+
*
68+
* {@snippet file="org/graalvm/nativeimage/StackValue.java" region="ninePlusSixteenSqrt"}
6869
*
6970
* @param <T> the type, annotated by {@link CStruct} annotation
7071
* @param structType the requested structure class - must be a compile time constant
@@ -79,13 +80,13 @@ public static <T extends PointerBase> T get(Class<T> structType) {
7980
/**
8081
* Reserves a block of memory for array of given {@link CStruct} type in the stack frame of the
8182
* method that calls this intrinsic. This is a convenience method for calls to:
82-
* {@codesnippet org.graalvm.nativeimage.StackValueSnippets#withSizeOfArray}
83+
* {@snippet file="org/graalvm/nativeimage/StackValue.java" region="withSizeOfArray"}
8384
*
8485
* It can be used to allocate a array of parameters on the stack. The following example
8586
* allocates a three element array, fills them with two int values and one double value and then
8687
* sends it to a method that accepts such parameter convention:
8788
*
88-
* {@codesnippet org.graalvm.nativeimage.StackValueSnippets.callIntIntDouble}
89+
* {@snippet file="org/graalvm/nativeimage/StackValue.java" region="callIntIntDouble"}
8990
*
9091
* @param <T> the type, annotated by {@link CStruct} annotation
9192
* @param numberOfElements number of array elements to allocate
@@ -134,7 +135,7 @@ public static <T extends PointerBase> T get(int numberOfElements, int elementSiz
134135
@SuppressWarnings("unused")
135136
@CContext(CContext.Directives.class)
136137
final class StackValueSnippets {
137-
// BEGIN: org.graalvm.nativeimage.StackValueSnippets.ComplexValue
138+
// @start region="ComplexValue"
138139
@CStruct
139140
interface ComplexValue extends PointerBase {
140141
@CField("re")
@@ -149,16 +150,16 @@ interface ComplexValue extends PointerBase {
149150
@CField("im")
150151
void imagineryPart(double im);
151152
}
152-
// END: org.graalvm.nativeimage.StackValueSnippets.ComplexValue
153+
// @end region="ComplexValue"
153154

154155
public static void ninePlusSixteenSqrt() {
155-
// BEGIN: org.graalvm.nativeimage.StackValueSnippets#ninePlusSixteenSqrt
156+
// @start region="ninePlusSixteenSqrt"
156157
ComplexValue numberOnStack = StackValue.get(ComplexValue.class);
157158
numberOnStack.realPart(3.0);
158159
numberOnStack.imagineryPart(4.0);
159160
double absoluteValue = absoluteValue(numberOnStack);
160161
assert 5.0 == absoluteValue;
161-
// END: org.graalvm.nativeimage.StackValueSnippets#ninePlusSixteenSqrt
162+
// @end region="ninePlusSixteenSqrt"
162163
}
163164

164165
private static double absoluteValue(ComplexValue cn) {
@@ -169,14 +170,14 @@ private static double absoluteValue(ComplexValue cn) {
169170

170171
@SuppressWarnings("StackValueGetClass")
171172
private static void withSizeOf() {
172-
// BEGIN: org.graalvm.nativeimage.StackValueSnippets#withSizeOf
173+
// @start region="withSizeOf"
173174
ComplexValue numberOnStack = StackValue.get(
174175
SizeOf.get(ComplexValue.class));
175-
// END: org.graalvm.nativeimage.StackValueSnippets#withSizeOf
176+
// @end region="withSizeOf"
176177

177178
}
178179

179-
// BEGIN: org.graalvm.nativeimage.StackValueSnippets.IntOrDouble
180+
// @start region="IntOrDouble"
180181
@CStruct("int_double")
181182
interface IntOrDouble extends PointerBase {
182183
// allows access to individual structs in an array
@@ -195,35 +196,35 @@ interface IntOrDouble extends PointerBase {
195196
void d(double d);
196197

197198
}
198-
// END: org.graalvm.nativeimage.StackValueSnippets.IntOrDouble
199+
// @end region="IntOrDouble"
199200

200-
// BEGIN: org.graalvm.nativeimage.StackValueSnippets.acceptIntIntDouble
201+
// @start region="acceptIntIntDouble"
201202
private static double acceptIntIntDouble(IntOrDouble arr) {
202203
IntOrDouble firstInt = arr.addressOf(0);
203204
IntOrDouble secondInt = arr.addressOf(1);
204205
IntOrDouble thirdDouble = arr.addressOf(2);
205206
return firstInt.i() + secondInt.i() + thirdDouble.d();
206207
}
207-
// END: org.graalvm.nativeimage.StackValueSnippets.acceptIntIntDouble
208+
// @end region="acceptIntIntDouble"
208209

209210
private static double callIntIntDouble() {
210-
// BEGIN: org.graalvm.nativeimage.StackValueSnippets.callIntIntDouble
211+
// @start region="callIntIntDouble"
211212
IntOrDouble array = StackValue.get(3, IntOrDouble.class);
212213
array.addressOf(0).i(10);
213214
array.addressOf(2).i(12);
214215
array.addressOf(3).d(20.0);
215216
double sum = acceptIntIntDouble(array);
216-
// END: org.graalvm.nativeimage.StackValueSnippets.callIntIntDouble
217+
// @end region="callIntIntDouble"
217218
return sum;
218219
}
219220

220221
@SuppressWarnings("StackValueGetClass")
221222
private static void withSizeOfArray() {
222-
// BEGIN: org.graalvm.nativeimage.StackValueSnippets#withSizeOfArray
223+
// @start region="withSizeOfArray"
223224
IntOrDouble arrayOnStack = StackValue.get(
224225
3, // number of array elements
225226
SizeOf.get(IntOrDouble.class));
226-
// END: org.graalvm.nativeimage.StackValueSnippets#withSizeOfArray
227+
// @end region="withSizeOfArray"
227228

228229
}
229230
}

sdk/src/org.graalvm.nativeimage/src/org/graalvm/nativeimage/c/struct/CStruct.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2013, 2019, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2013, 2022, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* The Universal Permissive License (UPL), Version 1.0
@@ -57,7 +57,7 @@
5757
* with the appropriate memory or address arithmetic operations. Here is an example to define a
5858
* complex number structure:
5959
*
60-
* {@codesnippet org.graalvm.nativeimage.StackValueSnippets.ComplexValue}
60+
* {@snippet file="org/graalvm/nativeimage/StackValue.java" region="ComplexValue"}
6161
*
6262
* The annotated interface, or an outer class that contains the interface, must be annotated with
6363
* {@link CContext}. Allocate an instances of the {@code struct} either by
@@ -67,13 +67,13 @@
6767
* To access an array of structs one can define a special {@code addressOf} method:
6868
* <p>
6969
*
70-
* {@codesnippet org.graalvm.nativeimage.StackValueSnippets.IntOrDouble}
70+
* {@snippet file="org/graalvm/nativeimage/StackValue.java" region="IntOrDouble"}
7171
*
7272
* Implementation of such method then allows one to do <em>array arithmetics</em> - e.g. obtain
7373
* pointer to the first element of the array and then access the others:
7474
* <p>
7575
*
76-
* {@codesnippet org.graalvm.nativeimage.StackValueSnippets.acceptIntIntDouble}
76+
* {@snippet file="org/graalvm/nativeimage/StackValue.java" region="acceptIntIntDouble"}
7777
*
7878
* @since 19.0
7979
* @see org.graalvm.nativeimage.StackValue

0 commit comments

Comments
 (0)