author | phh |
Sat, 30 Nov 2019 14:33:05 -0800 | |
changeset 59330 | 5b96c12f909d |
parent 47216 | 71c04702a3d5 |
permissions | -rw-r--r-- |
32641
ac2c73b45253
8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff
changeset
|
1 |
/* |
45028
b0ea3c0bfb81
8179889: Fix typographic errors in copyright headers
ihse
parents:
35784
diff
changeset
|
2 |
* Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved. |
35784 | 3 |
* |
4 |
* Redistribution and use in source and binary forms, with or without |
|
5 |
* modification, are permitted provided that the following conditions |
|
6 |
* are met: |
|
32641
ac2c73b45253
8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff
changeset
|
7 |
* |
35784 | 8 |
* - Redistributions of source code must retain the above copyright |
9 |
* notice, this list of conditions and the following disclaimer. |
|
10 |
* |
|
11 |
* - Redistributions in binary form must reproduce the above copyright |
|
12 |
* notice, this list of conditions and the following disclaimer in the |
|
13 |
* documentation and/or other materials provided with the distribution. |
|
32641
ac2c73b45253
8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff
changeset
|
14 |
* |
35784 | 15 |
* - Neither the name of Oracle nor the names of its |
16 |
* contributors may be used to endorse or promote products derived |
|
17 |
* from this software without specific prior written permission. |
|
32641
ac2c73b45253
8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff
changeset
|
18 |
* |
35784 | 19 |
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS |
20 |
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, |
|
21 |
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
|
22 |
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR |
|
23 |
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
|
24 |
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
|
25 |
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
|
26 |
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF |
|
27 |
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
|
28 |
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
|
29 |
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|
32641
ac2c73b45253
8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff
changeset
|
30 |
*/ |
ac2c73b45253
8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff
changeset
|
31 |
|
ac2c73b45253
8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff
changeset
|
32 |
#ifndef LIBJIMAGE_OSSUPPORT_HPP |
ac2c73b45253
8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff
changeset
|
33 |
#define LIBJIMAGE_OSSUPPORT_HPP |
ac2c73b45253
8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff
changeset
|
34 |
|
ac2c73b45253
8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff
changeset
|
35 |
#ifdef WIN32 |
ac2c73b45253
8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff
changeset
|
36 |
#include <Windows.h> |
ac2c73b45253
8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff
changeset
|
37 |
#else |
ac2c73b45253
8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff
changeset
|
38 |
#include <pthread.h> |
ac2c73b45253
8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff
changeset
|
39 |
#endif |
ac2c73b45253
8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff
changeset
|
40 |
|
ac2c73b45253
8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff
changeset
|
41 |
class osSupport { |
ac2c73b45253
8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff
changeset
|
42 |
public: |
ac2c73b45253
8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff
changeset
|
43 |
/** |
ac2c73b45253
8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff
changeset
|
44 |
* Open a regular file read-only. |
ac2c73b45253
8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff
changeset
|
45 |
* Return the file descriptor. |
ac2c73b45253
8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff
changeset
|
46 |
*/ |
ac2c73b45253
8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff
changeset
|
47 |
static jint openReadOnly(const char *path); |
ac2c73b45253
8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff
changeset
|
48 |
|
ac2c73b45253
8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff
changeset
|
49 |
/** |
ac2c73b45253
8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff
changeset
|
50 |
* Close a file descriptor. |
ac2c73b45253
8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff
changeset
|
51 |
*/ |
ac2c73b45253
8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff
changeset
|
52 |
static jint close(jint fd); |
ac2c73b45253
8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff
changeset
|
53 |
|
ac2c73b45253
8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff
changeset
|
54 |
/** |
ac2c73b45253
8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff
changeset
|
55 |
* Return the size of a regular file. |
ac2c73b45253
8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff
changeset
|
56 |
*/ |
ac2c73b45253
8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff
changeset
|
57 |
static jlong size(const char *path); |
ac2c73b45253
8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff
changeset
|
58 |
|
ac2c73b45253
8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff
changeset
|
59 |
/** |
ac2c73b45253
8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff
changeset
|
60 |
* Read nBytes at offset into a buffer. |
ac2c73b45253
8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff
changeset
|
61 |
*/ |
ac2c73b45253
8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff
changeset
|
62 |
static jlong read(jint fd, char *buf, jlong nBytes, jlong offset); |
ac2c73b45253
8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff
changeset
|
63 |
|
ac2c73b45253
8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff
changeset
|
64 |
/** |
ac2c73b45253
8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff
changeset
|
65 |
* Map nBytes at offset into memory and return the address. |
ac2c73b45253
8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff
changeset
|
66 |
* The system chooses the address. |
ac2c73b45253
8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff
changeset
|
67 |
*/ |
ac2c73b45253
8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff
changeset
|
68 |
static void* map_memory(jint fd, const char *filename, size_t file_offset, size_t bytes); |
ac2c73b45253
8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff
changeset
|
69 |
|
ac2c73b45253
8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff
changeset
|
70 |
/** |
ac2c73b45253
8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff
changeset
|
71 |
* Unmap nBytes of memory at address. |
ac2c73b45253
8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff
changeset
|
72 |
*/ |
ac2c73b45253
8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff
changeset
|
73 |
static int unmap_memory(void* addr, size_t bytes); |
ac2c73b45253
8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff
changeset
|
74 |
}; |
ac2c73b45253
8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff
changeset
|
75 |
|
ac2c73b45253
8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff
changeset
|
76 |
/** |
ac2c73b45253
8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff
changeset
|
77 |
* A CriticalSection to protect a small section of code. |
ac2c73b45253
8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff
changeset
|
78 |
*/ |
ac2c73b45253
8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff
changeset
|
79 |
class SimpleCriticalSection { |
ac2c73b45253
8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff
changeset
|
80 |
friend class SimpleCriticalSectionLock; |
ac2c73b45253
8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff
changeset
|
81 |
private: |
ac2c73b45253
8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff
changeset
|
82 |
void enter(); |
ac2c73b45253
8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff
changeset
|
83 |
void exit(); |
ac2c73b45253
8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff
changeset
|
84 |
public: |
ac2c73b45253
8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff
changeset
|
85 |
SimpleCriticalSection(); |
ac2c73b45253
8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff
changeset
|
86 |
//~SimpleCriticalSection(); // Cretes a dependency on Solaris on a C++ exit registration |
ac2c73b45253
8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff
changeset
|
87 |
|
ac2c73b45253
8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff
changeset
|
88 |
private: |
ac2c73b45253
8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff
changeset
|
89 |
#ifdef WIN32 |
ac2c73b45253
8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff
changeset
|
90 |
CRITICAL_SECTION critical_section; |
ac2c73b45253
8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff
changeset
|
91 |
#else |
ac2c73b45253
8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff
changeset
|
92 |
pthread_mutex_t mutex; |
ac2c73b45253
8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff
changeset
|
93 |
#endif // WIN32 |
ac2c73b45253
8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff
changeset
|
94 |
}; |
ac2c73b45253
8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff
changeset
|
95 |
|
ac2c73b45253
8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff
changeset
|
96 |
/** |
ac2c73b45253
8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff
changeset
|
97 |
* SimpleCriticalSectionLock instance. |
ac2c73b45253
8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff
changeset
|
98 |
* The constructor locks a SimpleCriticalSection and the |
ac2c73b45253
8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff
changeset
|
99 |
* destructor does the unlock. |
ac2c73b45253
8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff
changeset
|
100 |
*/ |
ac2c73b45253
8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff
changeset
|
101 |
class SimpleCriticalSectionLock { |
ac2c73b45253
8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff
changeset
|
102 |
private: |
ac2c73b45253
8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff
changeset
|
103 |
SimpleCriticalSection *lock; |
ac2c73b45253
8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff
changeset
|
104 |
public: |
ac2c73b45253
8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff
changeset
|
105 |
|
ac2c73b45253
8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff
changeset
|
106 |
SimpleCriticalSectionLock(SimpleCriticalSection *cslock) { |
ac2c73b45253
8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff
changeset
|
107 |
this->lock = cslock; |
ac2c73b45253
8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff
changeset
|
108 |
lock->enter(); |
ac2c73b45253
8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff
changeset
|
109 |
} |
ac2c73b45253
8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff
changeset
|
110 |
|
ac2c73b45253
8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff
changeset
|
111 |
~SimpleCriticalSectionLock() { |
ac2c73b45253
8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff
changeset
|
112 |
lock->exit(); |
ac2c73b45253
8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff
changeset
|
113 |
} |
ac2c73b45253
8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff
changeset
|
114 |
}; |
ac2c73b45253
8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff
changeset
|
115 |
|
ac2c73b45253
8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff
changeset
|
116 |
#endif // LIBJIMAGE_OSSUPPORT_HPP |