6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23
24 /*
25 * @test
26 * @enablePreview
27 * @bug 8248421
28 * @summary SystemCLinker should have a way to free memory allocated outside Java
29 * @run testng/othervm --enable-native-access=ALL-UNNAMED TestFree
30 */
31
32 import java.lang.foreign.MemorySegment;
33
34 import static org.testng.Assert.assertEquals;
35
36 public class TestFree extends NativeTestHelper {
37 public void test() throws Throwable {
38 String str = "hello world";
39 MemorySegment addr = allocateMemory(str.length() + 1);
40 addr.copyFrom(MemorySegment.ofArray(str.getBytes()));
41 addr.set(C_CHAR, str.length(), (byte)0);
42 assertEquals(str, addr.getUtf8String(0));
43 freeMemory(addr);
44 }
45 }
|
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23
24 /*
25 * @test
26 * @bug 8248421
27 * @summary SystemCLinker should have a way to free memory allocated outside Java
28 * @run testng/othervm --enable-native-access=ALL-UNNAMED TestFree
29 */
30
31 import java.lang.foreign.MemorySegment;
32
33 import static org.testng.Assert.assertEquals;
34
35 public class TestFree extends NativeTestHelper {
36 public void test() throws Throwable {
37 String str = "hello world";
38 MemorySegment addr = allocateMemory(str.length() + 1);
39 addr.copyFrom(MemorySegment.ofArray(str.getBytes()));
40 addr.set(C_CHAR, str.length(), (byte)0);
41 assertEquals(str, addr.getString(0));
42 freeMemory(addr);
43 }
44 }
|