comparison src/share/vm/graal/graalVmIds.cpp @ 3632:136ea96eb7f8

Remove the need for VmId (last usage was the constant pool).
author Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
date Mon, 14 Nov 2011 22:33:15 +0100
parents 75a99b4f1c98
children 076542d505cd
comparison
equal deleted inserted replaced
3630:3b18b27b0dd4 3632:136ea96eb7f8
26 #include "ci/ciUtilities.hpp" 26 #include "ci/ciUtilities.hpp"
27 27
28 // VmIds implementation 28 // VmIds implementation
29 29
30 GrowableArray<address>* VmIds::_stubs = NULL; 30 GrowableArray<address>* VmIds::_stubs = NULL;
31 GrowableArray<jobject>* VmIds::_localHandles = NULL;
32 31
33 32
34 void VmIds::initializeObjects() { 33 void VmIds::initializeObjects() {
35 if (_stubs == NULL) { 34 if (_stubs == NULL) {
36 assert(_localHandles == NULL, "inconsistent state"); 35 assert(_localHandles == NULL, "inconsistent state");
37 _stubs = new (ResourceObj::C_HEAP) GrowableArray<address> (64, true); 36 _stubs = new (ResourceObj::C_HEAP) GrowableArray<address> (64, true);
38 _localHandles = new (ResourceObj::C_HEAP) GrowableArray<jobject> (64, true);
39 } 37 }
40 assert(_localHandles->length() == 0, "invalid state"); 38 assert(_localHandles->length() == 0, "invalid state");
41 }
42
43 void VmIds::cleanupLocalObjects() {
44 for (int i = 0; i < _localHandles->length(); i++) {
45 JNIHandles::destroy_global(_localHandles->at(i));
46 }
47 _localHandles->clear();
48 } 39 }
49 40
50 jlong VmIds::addStub(address stub) { 41 jlong VmIds::addStub(address stub) {
51 assert(!_stubs->contains(stub), "duplicate stub"); 42 assert(!_stubs->contains(stub), "duplicate stub");
52 return _stubs->append(stub) | STUB; 43 return _stubs->append(stub) | STUB;
53 }
54
55 jlong VmIds::add(Handle obj, jlong type) {
56 assert(!obj.is_null(), "cannot add NULL handle");
57 int idx = -1;
58 for (int i = 0; i < _localHandles->length(); i++)
59 if (JNIHandles::resolve_non_null(_localHandles->at(i)) == obj()) {
60 idx = i;
61 break;
62 }
63 if (idx == -1) {
64 if (JavaThread::current()->thread_state() == _thread_in_vm) {
65 idx = _localHandles->append(JNIHandles::make_global(obj));
66 } else {
67 VM_ENTRY_MARK;
68 idx = _localHandles->append(JNIHandles::make_global(obj));
69 }
70 }
71 return idx | type;
72 } 44 }
73 45
74 address VmIds::getStub(jlong id) { 46 address VmIds::getStub(jlong id) {
75 assert((id & TYPE_MASK) == STUB, "wrong id type, STUB expected"); 47 assert((id & TYPE_MASK) == STUB, "wrong id type, STUB expected");
76 assert((id & ~TYPE_MASK) >= 0 && (id & ~TYPE_MASK) < _stubs->length(), "STUB index out of bounds"); 48 assert((id & ~TYPE_MASK) >= 0 && (id & ~TYPE_MASK) < _stubs->length(), "STUB index out of bounds");
77 return _stubs->at(id & ~TYPE_MASK); 49 return _stubs->at(id & ~TYPE_MASK);
78 } 50 }
79 51
80 oop VmIds::getObject(jlong id) {
81 assert((id & TYPE_MASK) != STUB, "wrong id type");
82 assert((id & ~TYPE_MASK) >= 0 && (id & ~TYPE_MASK) < _localHandles->length(), "index out of bounds");
83 return JNIHandles::resolve_non_null(_localHandles->at(id & ~TYPE_MASK));
84 }
85