Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/java/nio/MappedByteBuffer/MapSyncFail.java
41149 views
1
/*
2
* Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
*
5
* This code is free software; you can redistribute it and/or modify it
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
/* @test
25
* @summary Test failure paths for MAP_SYNC FileChannel.map of non-DAX files
26
* @modules java.base/jdk.internal.misc
27
* @run main MapSyncFail true
28
* @run main MapSyncFail false
29
*/
30
31
import java.io.*;
32
import java.nio.*;
33
import java.util.*;
34
import java.nio.channels.*;
35
import jdk.nio.mapmode.*;
36
import jdk.internal.misc.Unsafe;
37
38
public class MapSyncFail {
39
40
public static final int K = 1024;
41
42
public static void main(String[] args) throws Exception {
43
if (args.length != 1) {
44
throw new Exception("Expected true or false as argument");
45
}
46
boolean is_rw = Boolean.valueOf(args[0]);
47
FileChannel.MapMode mode = (is_rw ? ExtendedMapMode.READ_WRITE_SYNC : ExtendedMapMode.READ_ONLY_SYNC);
48
// it is assumed that /tmp is not a DAX file system
49
File file = File.createTempFile("MapSyncFail", null);
50
file.deleteOnExit();
51
long filesize = (8 * K);
52
try (RandomAccessFile raf = new RandomAccessFile(file, "rw")) {
53
raf.setLength(filesize);
54
FileChannel fc = raf.getChannel();
55
MappedByteBuffer mbb = fc.map(mode, 0, filesize);
56
} catch(IOException ioe) {
57
// when writeback is enabled for the current os/cpu
58
// combination the underlying mmap should be attempted and
59
// the map call should fail with IOException
60
if (!Unsafe.isWritebackEnabled()) {
61
throw new Exception("IOException not expected");
62
}
63
System.out.println("caught " + ioe);
64
ioe.printStackTrace();
65
return;
66
} catch (UnsupportedOperationException uoe) {
67
// when writeback is not enabled for the current os/cpu
68
// combination the mmap should not be attempted and the
69
// map call should fail with UnsupportedOperationException
70
71
if (Unsafe.isWritebackEnabled()) {
72
throw new Exception("UnsupportedOperationException not expected");
73
}
74
System.out.println("caught " + uoe);
75
uoe.printStackTrace();
76
return;
77
}
78
79
throw new Exception("expected IOException or UnsupportedOperationException");
80
}
81
}
82
83