Skip to content

Commit

Permalink
Merge pull request #2861 from acrowthe/add_constant_dynamic_slot_iter…
Browse files Browse the repository at this point in the history
…ator

WIP: Add constant dynamic slot iterator
  • Loading branch information
dmitripivkine committed Sep 26, 2018
2 parents 596a3df + e87d063 commit 8e4fb71
Show file tree
Hide file tree
Showing 11 changed files with 480 additions and 46 deletions.
1 change: 1 addition & 0 deletions runtime/gc_structs/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ add_library(j9gcstructs STATIC
ClassStaticsDeclarationOrderIterator.cpp
ClassStaticsIterator.cpp
ClassSuperclassesIterator.cpp
ConstantDynamicSlotIterator.cpp
ConstantPoolClassSlotIterator.cpp
ConstantPoolObjectSlotIterator.cpp
JVMTIObjectTagTableIterator.cpp
Expand Down
61 changes: 61 additions & 0 deletions runtime/gc_structs/ConstantDynamicSlotIterator.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@

/*******************************************************************************
* 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
* distribution and is available at https://www.eclipse.org/legal/epl-2.0/
* or the Apache License, Version 2.0 which accompanies this distribution and
* is available at https://www.apache.org/licenses/LICENSE-2.0.
*
* This Source Code may also be made available under the following
* Secondary Licenses when the conditions for such availability set
* forth in the Eclipse Public License, v. 2.0 are satisfied: GNU
* General Public License, version 2 with the GNU Classpath
* Exception [1] and GNU General Public License, version 2 with the
* OpenJDK Assembly Exception [2].
*
* [1] https://www.gnu.org/software/classpath/license.html
* [2] http://openjdk.java.net/legal/assembly-exception.html
*
* 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
*******************************************************************************/

/**
* @file
* @ingroup GC_Structs
*/

#include "j9.h"
#include "ModronAssertions.h"

#include "ConstantDynamicSlotIterator.hpp"


/**
* Scan the current constant dynamic slot
* @return slot value if it is not NULL
* @return exception otherwise
*/
j9object_t*
GC_ConstantDynamicSlotIterator::nextSlot(j9object_t *slotPtr) {
j9object_t *result;
switch (_condySlotState) {
case condy_slot_value:
result = &(((J9RAMConstantDynamicRef *) slotPtr)->value);
_condySlotState = condy_slot_exception;
break;
case condy_slot_exception:
result = &(((J9RAMConstantDynamicRef *) slotPtr)->exception);
_condySlotState = condy_slot_terminator;
break;
case condy_slot_terminator:
result = NULL;
_condySlotState = condy_slot_value;
break;
default:
Assert_MM_unreachable();
break;
}
return result;
}
58 changes: 58 additions & 0 deletions runtime/gc_structs/ConstantDynamicSlotIterator.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@

/*******************************************************************************
* 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
* distribution and is available at https://www.eclipse.org/legal/epl-2.0/
* or the Apache License, Version 2.0 which accompanies this distribution and
* is available at https://www.apache.org/licenses/LICENSE-2.0.
*
* This Source Code may also be made available under the following
* Secondary Licenses when the conditions for such availability set
* forth in the Eclipse Public License, v. 2.0 are satisfied: GNU
* General Public License, version 2 with the GNU Classpath
* Exception [1] and GNU General Public License, version 2 with the
* OpenJDK Assembly Exception [2].
*
* [1] https://www.gnu.org/software/classpath/license.html
* [2] http://openjdk.java.net/legal/assembly-exception.html
*
* 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
*******************************************************************************/

/**
* @file
* @ingroup GC_Structs
*/

#if !defined(CONSTANTDYNAMICSLOTITERATOR_HPP_)
#define CONSTANTDYNAMICSLOTITERATOR_HPP_

#include "j9.h"
#include "ModronAssertions.h"


/**
* Iterate over a constant dynamic object reference within the constant pool of a class.
*
* @see GC_ConstantPoolClassSlotIterator
* @ingroup GC_Structs
*/
class GC_ConstantDynamicSlotIterator {
private:
typedef enum {
condy_slot_value,
condy_slot_exception,
condy_slot_terminator
} CondySlotState;
CondySlotState _condySlotState;

public:
GC_ConstantDynamicSlotIterator() :
_condySlotState(condy_slot_value)
{ };

j9object_t *nextSlot(j9object_t *slotPtr);
};
#endif /* CONSTANTDYNAMICSLOTITERATOR_HPP_ */
27 changes: 16 additions & 11 deletions runtime/gc_structs/ConstantPoolObjectSlotIterator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ GC_ConstantPoolObjectSlotIterator::nextSlot() {
U_32 slotType;
j9object_t *slotPtr;
j9object_t *result = NULL;
bool nextSlot = true;

while (_cpEntryCount) {
if (0 == _cpDescriptionIndex) {
Expand All @@ -69,7 +68,11 @@ GC_ConstantPoolObjectSlotIterator::nextSlot() {
if (_condyOnly) {
/* Determine if the slot is constant dynamic */
if (slotType == J9CPTYPE_CONSTANT_DYNAMIC) {
result = scanCondySlot(slotPtr, &nextSlot);
if (NULL != (result = _constantDynamicSlotIterator.nextSlot(slotPtr))) {
/* Do not progress through the function.
* Avoids advancing the slot while a constant dynamic is being iterated */
return result;
}
}
} else {
/* Determine if the slot should be processed */
Expand All @@ -85,23 +88,25 @@ GC_ConstantPoolObjectSlotIterator::nextSlot() {
result = &(((J9RAMMethodHandleRef *) slotPtr)->methodHandle);
break;
case J9CPTYPE_CONSTANT_DYNAMIC:
result = scanCondySlot(slotPtr, &nextSlot);
if (NULL != (result = _constantDynamicSlotIterator.nextSlot(slotPtr))) {
/* Do not progress through the function.
* Avoids advancing the slot while a constant dynamic is being iterated */
return result;
}
break;
default:
break;
}

}

if (nextSlot) {
/* Adjust the CP slot and description information */
_cpEntry = (j9object_t *) (((U_8 *) _cpEntry)
+ sizeof(J9RAMConstantPoolItem));
_cpEntryCount -= 1;
/* 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;
}
_cpDescription >>= J9_CP_BITS_PER_DESCRIPTION;
_cpDescriptionIndex -= 1;

if (NULL != result) {
break;
Expand Down
38 changes: 4 additions & 34 deletions runtime/gc_structs/ConstantPoolObjectSlotIterator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,8 @@
#include "j2sever.h"
#include "ModronAssertions.h"

typedef enum {
condy_slot_value,
condy_slot_exception
} CondySlot;

#include "ConstantDynamicSlotIterator.hpp"

/**
* Iterate over object references (but not class references) in the constant pool of a class.
Expand All @@ -57,42 +55,14 @@ class GC_ConstantPoolObjectSlotIterator
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;
*nextSlot = true;
break;
default:
Assert_MM_unreachable();
break;
}
return result;
}
GC_ConstantDynamicSlotIterator _constantDynamicSlotIterator;

public:

GC_ConstantPoolObjectSlotIterator(J9JavaVM *vm, J9Class *clazz, bool condyOnly = false) :
_cpEntry((j9object_t *)J9_CP_FROM_CLASS(clazz)),
_cpEntryCount(clazz->romClass->ramConstantPoolCount),
_condySlotState(condy_slot_value)
_constantDynamicSlotIterator()
{
_condyOnly = condyOnly;
_cpEntryTotal = _cpEntryCount;
Expand Down
89 changes: 88 additions & 1 deletion test/functional/Java11andUp/playlist.xml
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,95 @@
<group>functional</group>
</groups>
<subsets>
<subset>SE110</subset>
<subset>11</subset>
</subsets>
</test>


<!--
Following test covers garbage collection of constant dynamics using several gc options.
Tests scenario for object, primitive and exception constant dynamics.
-->
<test>
<testCaseName>CondyGarbageCollection</testCaseName>
<variations>
<variation>NoOptions</variation>
<variation>-Xgcpolicy:optthruput</variation>
<variation>-Xgcpolicy:gencon</variation>
<variation>-Xgcpolicy:balanced</variation>
</variations>
<command>$(JAVA_COMMAND) $(JVM_OPTIONS) \
-cp $(Q)$(LIB_DIR)$(D)asm-7.0.jar$(P)$(RESOURCES_DIR)$(P)$(TESTNG)$(P)$(TEST_RESROOT)$(D)GeneralTest.jar$(Q) \
org.testng.TestNG -d $(REPORTDIR) $(Q)$(TEST_RESROOT)$(D)testng.xml$(Q) -testnames GarbageCollectionCondyTest \
-groups $(TEST_GROUP) \
-excludegroups $(DEFAULT_EXCLUDE); \
$(TEST_STATUS)
</command>

<levels>
<level>sanity</level>
</levels>
<groups>
<group>functional</group>
</groups>
<subsets>
<subset>11</subset>
</subsets>
</test>

<!--
Following test covers metronome garbage collection tests on linux_x86.
Tests scenarios for object, primitive and exception constant dynamics.
-->
<test>
<testCaseName>CondyGarbageCollectionMetronomeLinux</testCaseName>
<variations>
<variation>-Xgcpolicy:metronome</variation>
</variations>
<command>$(JAVA_COMMAND) $(JVM_OPTIONS) \
-cp $(Q)$(LIB_DIR)$(D)asm-7.0.jar$(P)$(RESOURCES_DIR)$(P)$(TESTNG)$(P)$(TEST_RESROOT)$(D)GeneralTest.jar$(Q) \
org.testng.TestNG -d $(REPORTDIR) $(Q)$(TEST_RESROOT)$(D)testng.xml$(Q) -testnames GarbageCollectionCondyTest \
-groups $(TEST_GROUP) \
-excludegroups $(DEFAULT_EXCLUDE); \
$(TEST_STATUS)
</command>
<platformRequirements>os.linux,arch.x86</platformRequirements>
<levels>
<level>sanity</level>
</levels>
<groups>
<group>functional</group>
</groups>
<subsets>
<subset>11</subset>
</subsets>
</test>

<!--
Following test covers metronome garbage collection tests on aix.
Tests scenarios for object, primitive and exception constant dynamics.
-->
<test>
<testCaseName>CondyGarbageCollectionMetronomeAIX</testCaseName>
<variations>
<variation>-Xgcpolicy:metronome</variation>
</variations>
<command>$(JAVA_COMMAND) $(JVM_OPTIONS) \
-cp $(Q)$(LIB_DIR)$(D)asm-7.0.jar$(P)$(RESOURCES_DIR)$(P)$(TESTNG)$(P)$(TEST_RESROOT)$(D)GeneralTest.jar$(Q) \
org.testng.TestNG -d $(REPORTDIR) $(Q)$(TEST_RESROOT)$(D)testng.xml$(Q) -testnames GarbageCollectionCondyTest \
-groups $(TEST_GROUP) \
-excludegroups $(DEFAULT_EXCLUDE); \
$(TEST_STATUS)
</command>
<platformRequirements>os.aix</platformRequirements>
<levels>
<level>sanity</level>
</levels>
<groups>
<group>functional</group>
</groups>
<subsets>
<subset>11</subset>
</subsets>
</test>
</playlist>
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,7 @@ public static double bootstrap_constant_double(MethodHandles.Lookup l, String na
public static long bootstrap_constant_long(MethodHandles.Lookup l, String name, Class<?> c, long v) {
return v;
}
public static int bootstrap_constant_int_exception(MethodHandles.Lookup l, String name, Class<?> c, int v) throws Exception {
throw new Exception();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*******************************************************************************
* Copyright (c) 2018, 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
* distribution and is available at https://www.eclipse.org/legal/epl-2.0/
* or the Apache License, Version 2.0 which accompanies this distribution and
* is available at https://www.apache.org/licenses/LICENSE-2.0.
*
* This Source Code may also be made available under the following
* Secondary Licenses when the conditions for such availability set
* forth in the Eclipse Public License, v. 2.0 are satisfied: GNU
* General Public License, version 2 with the GNU Classpath
* Exception [1] and GNU General Public License, version 2 with the
* OpenJDK Assembly Exception [2].
*
* [1] https://www.gnu.org/software/classpath/license.html
* [2] http://openjdk.java.net/legal/assembly-exception.html
*
* 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
*******************************************************************************/
package org.openj9.test.condy;


public class CondyClassLoader extends ClassLoader {
public Class<?> load(String name, byte[] bytes) {
return (Class<?>) defineClass(name, bytes, 0, bytes.length);
}
}
Loading

0 comments on commit 8e4fb71

Please sign in to comment.