Skip to content

Commit a0787ab

Browse files
Ershany-IBMtajila
authored andcommitted
Made a jvmimage_api.h and jvmimage.h (eclipse-openj9#4)
Signed-off-by: Brady Jessup <[email protected]>
1 parent 4404901 commit a0787ab

File tree

5 files changed

+151
-88
lines changed

5 files changed

+151
-88
lines changed

runtime/oti/j9protos.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,8 @@ typedef J9RelocationStruct relocateStruct;
141141

142142
#include "simplepool_api.h"
143143

144+
#include "jvmimage_api.h"
145+
144146
#ifdef __cplusplus
145147
extern "C" {
146148
#endif

runtime/oti/jvmimage.h

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*******************************************************************************
2+
* Copyright (c) 1991, 2019 IBM Corp. and others
3+
*
4+
* This program and the accompanying materials are made available under
5+
* the terms of the Eclipse Public License 2.0 which accompanies this
6+
* distribution and is available at https://www.eclipse.org/legal/epl-2.0/
7+
* or the Apache License, Version 2.0 which accompanies this distribution and
8+
* is available at https://www.apache.org/licenses/LICENSE-2.0.
9+
*
10+
* This Source Code may also be made available under the following
11+
* Secondary Licenses when the conditions for such availability set
12+
* forth in the Eclipse Public License, v. 2.0 are satisfied: GNU
13+
* General Public License, version 2 with the GNU Classpath
14+
* Exception [1] and GNU General Public License, version 2 with the
15+
* OpenJDK Assembly Exception [2].
16+
*
17+
* [1] https://www.gnu.org/software/classpath/license.html
18+
* [2] http://openjdk.java.net/legal/assembly-exception.html
19+
*
20+
* SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 OR LicenseRef-GPL-2.0 WITH Assembly-exception
21+
*******************************************************************************/
22+
23+
#ifndef jvmimage_h
24+
#define jvmimage_h
25+
26+
#define OMRPORT_FROM_IMAGE JVMImage::getInstance()->getPortLibrary();
27+
28+
#endif

runtime/oti/jvmimage_api.h

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/*******************************************************************************
2+
* Copyright (c) 1991, 2019 IBM Corp. and others
3+
*
4+
* This program and the accompanying materials are made available under
5+
* the terms of the Eclipse Public License 2.0 which accompanies this
6+
* distribution and is available at https://www.eclipse.org/legal/epl-2.0/
7+
* or the Apache License, Version 2.0 which accompanies this distribution and
8+
* is available at https://www.apache.org/licenses/LICENSE-2.0.
9+
*
10+
* This Source Code may also be made available under the following
11+
* Secondary Licenses when the conditions for such availability set
12+
* forth in the Eclipse Public License, v. 2.0 are satisfied: GNU
13+
* General Public License, version 2 with the GNU Classpath
14+
* Exception [1] and GNU General Public License, version 2 with the
15+
* OpenJDK Assembly Exception [2].
16+
*
17+
* [1] https://www.gnu.org/software/classpath/license.html
18+
* [2] http://openjdk.java.net/legal/assembly-exception.html
19+
*
20+
* SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 OR LicenseRef-GPL-2.0 WITH Assembly-exception
21+
*******************************************************************************/
22+
23+
#ifndef jvmimage_api_h
24+
#define jvmimage_api_h
25+
26+
#include "j9.h"
27+
#include "j9comp.h"
28+
#include "jvmimage.h"
29+
30+
#ifdef __cplusplus
31+
extern "C" {
32+
#endif
33+
34+
/*
35+
* Allocate memory in heap image
36+
*
37+
* @param portLibrary[in] the default port library
38+
* @param byteAmount[in] size to allocate
39+
* @param callSite[in] location memory alloc is called from
40+
* @param category[in] category of memory alloc
41+
*
42+
* returns pointer to allocated memory on success, NULL on failure
43+
*/
44+
void* image_mem_allocate_memory(struct OMRPortLibrary* portLibrary, uintptr_t byteAmount, const char* callSite, uint32_t category);
45+
46+
/*
47+
* Free memory in heap image
48+
*
49+
* @param portLibrary[in] the default port library
50+
* @param memoryPointer[in] pointer to address for free
51+
*/
52+
void image_mem_free_memory(struct OMRPortLibrary* portLibrary, void* memoryPointer);
53+
54+
/*
55+
* Creates and allocates the jvm image and its' heap
56+
*
57+
* @param vm[in] the default port library
58+
*/
59+
void create_and_allocate_jvm_image(J9JavaVM *vm);
60+
61+
#ifdef __cplusplus
62+
}
63+
#endif
64+
65+
#endif /* jvmimage_api_h */

runtime/oti/vm_api.h

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -4226,35 +4226,6 @@ attachVMToOMR(J9JavaVM *vm);
42264226
void
42274227
detachVMFromOMR(J9JavaVM *vm);
42284228

4229-
/* ------------------- JVMImage.cpp ----------------- */
4230-
4231-
/*
4232-
* Allocate memory in heap image
4233-
*
4234-
* @param portLibrary[in] the default port library
4235-
* @param byteAmount[in] size to allocate
4236-
* @param callSite[in] location memory alloc is called from
4237-
* @param category[in] category of memory alloc
4238-
*
4239-
* returns pointer to allocated memory on success, NULL on failure
4240-
*/
4241-
void* image_mem_allocate_memory(struct OMRPortLibrary* portLibrary, uintptr_t byteAmount, const char* callSite, uint32_t category);
4242-
4243-
/*
4244-
* Free memory in heap image
4245-
*
4246-
* @param portLibrary[in] the default port library
4247-
* @param memoryPointer[in] pointer to address for free
4248-
*/
4249-
void image_mem_free_memory(struct OMRPortLibrary* portLibrary, void* memoryPointer);
4250-
4251-
/*
4252-
* Creates and allocates the jvm image and its heap
4253-
*
4254-
* @param vm[in] the default port library
4255-
*/
4256-
void create_and_allocate_jvm_image(J9JavaVM *vm);
4257-
42584229
/* ------------------- callin.cpp ----------------- */
42594230

42604231
/**

runtime/vm/JVMImage.cpp

Lines changed: 56 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,11 @@
2222

2323
#include "JVMImage.hpp"
2424

25-
#define OMRPORT_FROM_IMAGE JVMImage::getInstance()->getPortLibrary();
26-
2725
JVMImage *JVMImage::_jvmInstance = NULL;
2826
const UDATA JVMImage::INITIAL_IMAGE_SIZE = 1024;
2927

3028
JVMImage::JVMImage(J9JavaVM *javaVM) :
31-
_heap(NULL),
29+
_heap(NULL),
3230
_currentImageSize(0),
3331
_isImageAllocated(false),
3432
_dumpFileName(NULL)
@@ -57,44 +55,43 @@ JVMImage::initializeMonitor()
5755
JVMImage *
5856
JVMImage::createInstance(J9JavaVM *vm)
5957
{
60-
PORT_ACCESS_FROM_JAVAVM(vm);
61-
62-
_jvmInstance = (JVMImage *)j9mem_allocate_memory(sizeof(JVMImage), J9MEM_CATEGORY_CLASSES);
63-
if (_jvmInstance != NULL) {
64-
new(_jvmInstance) JVMImage(vm);
65-
}
66-
67-
return _jvmInstance;
58+
PORT_ACCESS_FROM_JAVAVM(vm);
59+
60+
_jvmInstance = (JVMImage *)j9mem_allocate_memory(sizeof(JVMImage), J9MEM_CATEGORY_CLASSES);
61+
if (_jvmInstance != NULL) {
62+
new(_jvmInstance) JVMImage(vm);
63+
}
64+
65+
return _jvmInstance;
6866
}
6967

7068
JVMImage *
7169
JVMImage::getInstance()
7270
{
73-
return _jvmInstance;
71+
return _jvmInstance;
7472
}
7573

7674
void
7775
JVMImage::allocateImageMemory(J9JavaVM *vm, UDATA size)
7876
{
79-
PORT_ACCESS_FROM_JAVAVM(vm);
80-
81-
J9Heap *allocPtr = (J9Heap*)j9mem_allocate_memory(size, J9MEM_CATEGORY_CLASSES);
82-
if (allocPtr == NULL) {
83-
// Memory allocation failed
84-
return;
85-
}
86-
87-
_heap = j9heap_create(allocPtr, size, 0);
88-
if (_heap == NULL) {
89-
// Heap creation failed
90-
j9mem_free_memory((void *) allocPtr);
91-
return;
92-
}
93-
94-
_currentImageSize = size;
95-
_isImageAllocated = true;
96-
initializeMonitor();
97-
77+
PORT_ACCESS_FROM_JAVAVM(vm);
78+
79+
J9Heap *allocPtr = (J9Heap*)j9mem_allocate_memory(size, J9MEM_CATEGORY_CLASSES);
80+
if (allocPtr == NULL) {
81+
// Memory allocation failed
82+
return;
83+
}
84+
85+
_heap = j9heap_create(allocPtr, size, 0);
86+
if (_heap == NULL) {
87+
// Heap creation failed
88+
j9mem_free_memory((void *) allocPtr);
89+
return;
90+
}
91+
92+
_currentImageSize = size;
93+
_isImageAllocated = true;
94+
initializeMonitor();
9895
}
9996

10097
void
@@ -133,57 +130,57 @@ JVMImage::freeSubAllocatedMemory(void* address)
133130
void
134131
JVMImage::readImageFromFile()
135132
{
136-
OMRPORT_ACCESS_FROM_OMRPORT(getPortLibrary());
133+
OMRPORT_ACCESS_FROM_OMRPORT(getPortLibrary());
137134

138135
// TODO: The size will need to be very large or dynamically based on whatever is written to the dump
139-
char imageBuffer[JVMImage::INITIAL_IMAGE_SIZE];
140-
memset(imageBuffer, 0, sizeof(imageBuffer));
136+
char imageBuffer[JVMImage::INITIAL_IMAGE_SIZE];
137+
memset(imageBuffer, 0, sizeof(imageBuffer));
141138

142-
intptr_t fileDescriptor = omrfile_open(_dumpFileName, EsOpenRead, 0444);
143-
if (fileDescriptor == -1) {
144-
// Failure to open file
145-
}
139+
intptr_t fileDescriptor = omrfile_open(_dumpFileName, EsOpenRead, 0444);
140+
if (fileDescriptor == -1) {
141+
// Failure to open file
142+
}
146143

147-
intptr_t bytesRead = omrfile_read(fileDescriptor, imageBuffer, sizeof(imageBuffer));
148-
if (bytesRead == -1) {
149-
// Failure to read the image
150-
}
144+
intptr_t bytesRead = omrfile_read(fileDescriptor, imageBuffer, sizeof(imageBuffer));
145+
if (bytesRead == -1) {
146+
// Failure to read the image
147+
}
151148

152-
if (omrfile_close(fileDescriptor) != 0) {
153-
// Failure to close
154-
}
149+
if (omrfile_close(fileDescriptor) != 0) {
150+
// Failure to close
151+
}
155152

156-
// TODO: Finally load the JVMImage using the data we read from the image
153+
// TODO: Finally load the JVMImage using the data we read from the image
157154
}
158155

159156
void
160157
JVMImage::storeImageInFile()
161158
{
162-
OMRPORT_ACCESS_FROM_OMRPORT(getPortLibrary());
159+
OMRPORT_ACCESS_FROM_OMRPORT(getPortLibrary());
163160

164161
if (!_isImageAllocated) {
165162
// Nothing to dump
166163
}
167164

168-
intptr_t fileDescriptor = omrfile_open(_dumpFileName, EsOpenCreate | EsOpenWrite | EsOpenTruncate, 0666);
169-
if (fileDescriptor == -1) {
170-
// Failure to open file
171-
}
165+
intptr_t fileDescriptor = omrfile_open(_dumpFileName, EsOpenCreate | EsOpenWrite | EsOpenTruncate, 0666);
166+
if (fileDescriptor == -1) {
167+
// Failure to open file
168+
}
172169

173-
if (omrfile_write(fileDescriptor, (void*)_heap, _currentImageSize) != (intptr_t)_currentImageSize) {
174-
// Failure to write to the file
175-
}
170+
if (omrfile_write(fileDescriptor, (void*)_heap, _currentImageSize) != (intptr_t)_currentImageSize) {
171+
// Failure to write to the file
172+
}
176173

177-
if (omrfile_close(fileDescriptor) != 0) {
178-
// Failure to close
179-
}
174+
if (omrfile_close(fileDescriptor) != 0) {
175+
// Failure to close
176+
}
180177
}
181178

182179
extern "C" void
183180
create_and_allocate_jvm_image(J9JavaVM *vm)
184181
{
185-
JVMImage *jvmImage = JVMImage::createInstance(vm);
186-
jvmImage->allocateImageMemory(vm, JVMImage::INITIAL_IMAGE_SIZE);
182+
JVMImage *jvmImage = JVMImage::createInstance(vm);
183+
jvmImage->allocateImageMemory(vm, JVMImage::INITIAL_IMAGE_SIZE);
187184
}
188185

189186
extern "C" void *

0 commit comments

Comments
 (0)