Skip to content

Commit

Permalink
Add Constant Dynamic in GC Implementation
Browse files Browse the repository at this point in the history
Implemented condy iterator in constant pool and added it to the GC
Implementation
(/runtime/gc_glue_java/CollectorLanguageInterfaceImpl.cpp).

This is the first part of two changes, the next change will check if the
class contains any Condy cp entries

Signed-off-by: Charles_Zheng <[email protected]>
  • Loading branch information
Charles_Zheng authored and Charles_Zheng committed Aug 23, 2018
1 parent 63c305a commit c28567a
Show file tree
Hide file tree
Showing 5 changed files with 119 additions and 29 deletions.
24 changes: 23 additions & 1 deletion runtime/gc_glue_java/CollectorLanguageInterfaceImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,10 @@ MM_CollectorLanguageInterfaceImpl::scavenger_scavengeIndirectObjectSlots(MM_Envi
while((slotPtr = classStaticsIterator.nextSlot()) != NULL) {
shouldBeRemembered = _extensions->scavenger->copyObjectSlot(env, slotPtr) || shouldBeRemembered;
}
GC_ConstantPoolObjectSlotIterator constantPoolObjectSlotIterator((J9JavaVM*)_omrVM->_language_vm, classToScan, true);
while ((slotPtr = constantPoolObjectSlotIterator.nextSlot()) != NULL) {
shouldBeRemembered = _extensions->scavenger->copyObjectSlot(env, slotPtr) || shouldBeRemembered;
}
shouldBeRemembered = _extensions->scavenger->copyObjectSlot(env, (omrobjectptr_t *)&(classToScan->classObject)) || shouldBeRemembered;

classToScan = classToScan->replacedClass;
Expand All @@ -415,7 +419,7 @@ MM_CollectorLanguageInterfaceImpl::scavenger_hasIndirectReferentsInNewSpace(MM_E
return true;
}

/* Iterate though Class Statics */
/* Iterate though Class Statics and Constant Dynamics*/
do {
omrobjectptr_t *slotPtr = NULL;
GC_ClassStaticsIterator classStaticsIterator(env, classToScan);
Expand All @@ -428,6 +432,16 @@ MM_CollectorLanguageInterfaceImpl::scavenger_hasIndirectReferentsInNewSpace(MM_E
}
}
}
GC_ConstantPoolObjectSlotIterator constantPoolObjectSlotIterator((J9JavaVM*)_omrVM->_language_vm, classToScan, true);
while (NULL != (slotPtr = (omrobjectptr_t*)constantPoolObjectSlotIterator.nextSlot())) {
omrobjectptr_t objectPtr = *slotPtr;
if (NULL != objectPtr) {
if (_extensions->scavenger->isObjectInNewSpace(objectPtr)){
Assert_MM_false(_extensions->scavenger->isObjectInEvacuateMemory(objectPtr));
return true;
}
}
}
classToScan = classToScan->replacedClass;
} while (NULL != classToScan);

Expand All @@ -447,6 +461,10 @@ MM_CollectorLanguageInterfaceImpl::scavenger_fixupIndirectObjectSlots(MM_Environ
while((slotPtr = classStaticsIterator.nextSlot()) != NULL) {
_extensions->scavenger->fixupSlotWithoutCompression(slotPtr);
}
GC_ConstantPoolObjectSlotIterator constantPoolObjectSlotIterator((J9JavaVM*)_omrVM->_language_vm, classToScan, true);
while ((slotPtr = constantPoolObjectSlotIterator.nextSlot()) != NULL) {
_extensions->scavenger->fixupSlotWithoutCompression(slotPtr);
}
_extensions->scavenger->fixupSlotWithoutCompression((omrobjectptr_t *)&(classToScan->classObject));
classToScan = classToScan->replacedClass;
} while (NULL != classToScan);
Expand All @@ -465,6 +483,10 @@ MM_CollectorLanguageInterfaceImpl::scavenger_backOutIndirectObjectSlots(MM_Envir
while((slotPtr = classStaticsIterator.nextSlot()) != NULL) {
_extensions->scavenger->backOutFixSlotWithoutCompression(slotPtr);
}
GC_ConstantPoolObjectSlotIterator constantPoolObjectSlotIterator((J9JavaVM*)_omrVM->_language_vm, classToScan, true);
while ((slotPtr = constantPoolObjectSlotIterator.nextSlot()) != NULL) {
_extensions->scavenger->backOutFixSlotWithoutCompression(slotPtr);
}
_extensions->scavenger->backOutFixSlotWithoutCompression((omrobjectptr_t *)&(classToScan->classObject));
classToScan = classToScan->replacedClass;
} while (NULL != classToScan);
Expand Down
4 changes: 2 additions & 2 deletions runtime/gc_structs/ClassIterator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ class GC_ClassIterator {
, _state(classiterator_state_start)
, _scanIndex(0)
, _classStaticsIterator(env, clazz)
, _constantPoolObjectSlotIterator(clazz)
, _constantPoolObjectSlotIterator((J9JavaVM *)env->getLanguageVM(), clazz)
, _callSitesIterator(clazz)
, _methodTypesIterator(clazz->romClass->methodTypeCount, clazz->methodTypes)
, _varHandlesMethodTypesIterator(clazz->romClass->varHandleMethodTypeCount, clazz->varHandleMethodTypes)
Expand All @@ -92,7 +92,7 @@ class GC_ClassIterator {
, _state(classiterator_state_start)
, _scanIndex(0)
, _classStaticsIterator(extensions, clazz)
, _constantPoolObjectSlotIterator(clazz)
, _constantPoolObjectSlotIterator((J9JavaVM *)extensions->getOmrVM()->_language_vm, clazz)
, _callSitesIterator(clazz)
, _methodTypesIterator(clazz->romClass->methodTypeCount, clazz->methodTypes)
, _varHandlesMethodTypesIterator(clazz->romClass->varHandleMethodTypeCount, clazz->varHandleMethodTypes)
Expand Down
64 changes: 43 additions & 21 deletions runtime/gc_structs/ConstantPoolObjectSlotIterator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,27 @@


/**
* If condyOnly flag is not set:
* @return the next object slot in the constant pool
* @return NULL if there are no more object references
*
* If condyOnly flag is set and Java version is SE11 and above:
* @return the next Condy reference from the constant pool
* @return NULL if there are no more references
*/
j9object_t *
GC_ConstantPoolObjectSlotIterator::nextSlot()
{
GC_ConstantPoolObjectSlotIterator::nextSlot() {
/* Return NULL if _condyOnly is true but system is not condy-enabled */
if (_condyOnly && !_condyEnabled) {
return NULL;
}
U_32 slotType;
j9object_t *slotPtr;
j9object_t *result = NULL;
bool nextSlot = true;

while(_cpEntryCount) {
if(0 == _cpDescriptionIndex) {
while (_cpEntryCount) {
if (0 == _cpDescriptionIndex) {
_cpDescription = *_cpDescriptionSlots;
_cpDescriptionSlots += 1;
_cpDescriptionIndex = J9_CP_DESCRIPTIONS_PER_U32;
Expand All @@ -55,15 +64,17 @@ GC_ConstantPoolObjectSlotIterator::nextSlot()
slotType = _cpDescription & J9_CP_DESCRIPTION_MASK;
slotPtr = _cpEntry;

/* Adjust the CP slot and description information */
_cpEntry = (j9object_t *)( ((U_8 *)_cpEntry) + sizeof(J9RAMConstantPoolItem) );
_cpEntryCount -= 1;

_cpDescription >>= J9_CP_BITS_PER_DESCRIPTION;
_cpDescriptionIndex -= 1;

/* Determine if the slot should be processed */
switch (slotType) {
/* If _condyOnly is TRUE, return the next constant dynamic slot in constant pool
* Otherwise return the next object */
if (_condyOnly) {
/* Determine if the slot is constant dynamic */
if (slotType == J9CPTYPE_CONSTANT_DYNAMIC) {
result = scanCondySlot(slotPtr, &nextSlot);
break;
}
} else {
/* Determine if the slot should be processed */
switch (slotType) {
case J9CPTYPE_STRING: /* fall through */
case J9CPTYPE_ANNOTATION_UTF8:
result = &(((J9RAMStringRef *) slotPtr)->stringObject);
Expand All @@ -75,19 +86,30 @@ GC_ConstantPoolObjectSlotIterator::nextSlot()
result = &(((J9RAMMethodHandleRef *) slotPtr)->methodHandle);
break;
case J9CPTYPE_CONSTANT_DYNAMIC:
if (NULL != ((J9RAMConstantDynamicRef *) slotPtr)->value) {
result = &(((J9RAMConstantDynamicRef *) slotPtr)->value);
} else {
result = &(((J9RAMConstantDynamicRef *) slotPtr)->exception);
}
result = scanCondySlot(slotPtr, &nextSlot);
break;
default:
continue;
break;
}

}

if (nextSlot) {
/* Adjust the CP slot and description information */
_cpEntry = (j9object_t *) (((U_8 *) _cpEntry)
+ sizeof(J9RAMConstantPoolItem));
_cpEntryCount -= 1;

_cpDescription >>= J9_CP_BITS_PER_DESCRIPTION;
_cpDescriptionIndex -= 1;
}

if (NULL != result) {
break;
}

return result;
}
return NULL;
return result;
}

bool
Expand Down
54 changes: 50 additions & 4 deletions runtime/gc_structs/ConstantPoolObjectSlotIterator.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

/*******************************************************************************
* Copyright (c) 1991, 2014 IBM Corp. and others
* Copyright (c) 1991, 2018 IBM Corp. and others
*
* This program and the accompanying materials are made available under
* the terms of the Eclipse Public License 2.0 which accompanies this
Expand Down Expand Up @@ -33,6 +33,13 @@
#include "j9cfg.h"
#include "j9cp.h"
#include "modron.h"
#include "j2sever.h"
#include "ModronAssertions.h"

typedef enum {
condy_slot_value,
condy_slot_exception
} CondySlot;

/**
* Iterate over object references (but not class references) in the constant pool of a class.
Expand All @@ -48,18 +55,56 @@ class GC_ConstantPoolObjectSlotIterator
U_32 *_cpDescriptionSlots;
U_32 _cpDescription;
UDATA _cpDescriptionIndex;
bool _condyOnly;
bool _condyEnabled;
CondySlot _condySlotState;


private:
/**
* Scan the current constant dynamic slot
* @return slot value if it is not NULL
* @return exception otherwise
*/
MMINLINE
j9object_t* scanCondySlot(j9object_t *slotPtr, bool *nextSlot) {
j9object_t *result;
switch (_condySlotState) {
case condy_slot_value:
result = &(((J9RAMConstantDynamicRef *) slotPtr)->value);
_condySlotState = condy_slot_exception;
*nextSlot = false;
break;
case condy_slot_exception:
result = &(((J9RAMConstantDynamicRef *) slotPtr)->exception);
_condySlotState = condy_slot_value;
break;
default:
Assert_MM_unreachable();
break;
}
return result;
}

public:
GC_ConstantPoolObjectSlotIterator(J9Class *clazz) :

GC_ConstantPoolObjectSlotIterator(J9JavaVM *vm, J9Class *clazz, bool condyOnly = false) :
_cpEntry((j9object_t *)J9_CP_FROM_CLASS(clazz)),
_cpEntryCount(clazz->romClass->ramConstantPoolCount)
_cpEntryCount(clazz->romClass->ramConstantPoolCount),
_condySlotState(condy_slot_value)
{
_condyOnly = condyOnly;
_cpEntryTotal = _cpEntryCount;
if(_cpEntryCount) {
_cpDescriptionSlots = SRP_PTR_GET(&clazz->romClass->cpShapeDescription, U_32 *);
_cpDescriptionIndex = 0;
}

/* Check if the system is condy-enabled */
if (J2SE_VERSION(vm) < J2SE_V11) {
_condyEnabled = false;
} else {
_condyEnabled = true;
}
};

/**
Expand Down Expand Up @@ -90,6 +135,7 @@ class GC_ConstantPoolObjectSlotIterator
* @param slot[in] The slot pointer which is to be returned by the next call to nextSlot
*/
void setNextSlot(j9object_t *slot);

};

#endif /* CONSTANTPOOLOBJECTSLOTITERATOR_HPP_ */
2 changes: 1 addition & 1 deletion runtime/gc_vlhgc/CopyForwardScheme.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4670,7 +4670,7 @@ MM_CopyForwardScheme::verifyClassObjectSlots(MM_EnvironmentVLHGC *env, J9Object
/* we can safely ignore any classes referenced by the constant pool, since
* these are guaranteed to be referenced by our class loader
*/
GC_ConstantPoolObjectSlotIterator constantPoolIterator(classPtr);
GC_ConstantPoolObjectSlotIterator constantPoolIterator(_javaVM, classPtr);
while(NULL != (slotPtr = constantPoolIterator.nextSlot())) {
J9Object *dstObject = *slotPtr;
if(!_abortInProgress && verifyIsPointerInEvacute(env, dstObject)) {
Expand Down

0 comments on commit c28567a

Please sign in to comment.