Skip to content

Commit

Permalink
Merge pull request #6570 from Charlmzz/type-layout
Browse files Browse the repository at this point in the history
Add enumerateFields api to create a TypeLayout object
  • Loading branch information
andrewcraik authored Oct 30, 2019
2 parents 99e396a + 954259e commit 0cab97e
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 0 deletions.
56 changes: 56 additions & 0 deletions runtime/compiler/env/J9ClassEnv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,13 @@
#include "env/ClassEnv.hpp"
#include "env/CompilerEnv.hpp"
#include "env/jittypes.h"
#include "env/TypeLayout.hpp"
#include "env/VMJ9.h"
#include "j9.h"
#include "j9protos.h"
#include "j9cp.h"
#include "j9cfg.h"
#include "j9fieldsInfo.h"
#include "rommeth.h"


Expand Down Expand Up @@ -409,6 +411,60 @@ J9::ClassEnv::isAnonymousClass(TR::Compilation *comp, TR_OpaqueClassBlock *clazz
return comp->fej9()->isAnonymousClass(clazz);
}

const TR::TypeLayout*
J9::ClassEnv::enumerateFields(TR::Region& region, TR_OpaqueClassBlock * opaqueClazz, TR::Compilation *comp)
{
J9Class *clazz = (J9Class*)opaqueClazz;
TR_VMFieldsInfo fieldsInfo(comp, clazz, 1, stackAlloc);
ListIterator<TR_VMField> iter(fieldsInfo.getFields());
TR::TypeLayoutBuilder tlb(region);
for (TR_VMField *field = iter.getFirst(); field; field = iter.getNext())
{
char *signature = field->signature;
char charSignature = *signature;
TR::DataType dataType;
switch(charSignature)
{
case 'Z':
case 'B':
case 'C':
case 'S':
case 'I':
{
dataType = TR::Int32;
break;
}
case 'J':
{
dataType = TR::Int64;
break;
}
case 'F':
{
dataType = TR::Float;
break;
}
case 'D':
{
dataType = TR::Double;
break;
}
case 'L':
case '[':
{
dataType = TR::Address;
break;
}
}
size_t nameSize = strlen(field->name)+1;
char *fieldName = new (region) char[nameSize];
strncpy(fieldName, field->name, nameSize);
TR_ASSERT_FATAL(fieldName[nameSize-1] == '\0', "fieldName buffer was too small.");
int32_t offset = field->offset + TR::Compiler->om.objectHeaderSizeInBytes();
tlb.add(TR::TypeLayoutEntry(dataType, offset, fieldName));
}
return tlb.build();
}

int32_t
J9::ClassEnv::vTableSlot(TR::Compilation *comp, TR_OpaqueMethodBlock *method, TR_OpaqueClassBlock *clazz)
Expand Down
16 changes: 16 additions & 0 deletions runtime/compiler/env/J9ClassEnv.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ namespace J9 { typedef J9::ClassEnv ClassEnvConnector; }
#include "j9.h"

namespace TR { class SymbolReference; }
namespace TR { class TypeLayout; }
namespace TR { class Region; }

namespace J9
{
Expand Down Expand Up @@ -102,6 +104,20 @@ class OMR_EXTENSIBLE ClassEnv : public OMR::ClassEnvConnector
bool jitStaticsAreSame(TR::Compilation *comp, TR_ResolvedMethod * method1, int32_t cpIndex1, TR_ResolvedMethod * method2, int32_t cpIndex2);
bool jitFieldsAreSame(TR::Compilation *comp, TR_ResolvedMethod * method1, int32_t cpIndex1, TR_ResolvedMethod * method2, int32_t cpIndex2, int32_t isStatic);

/** \brief
* Populates a TypeLayout object.
*
* \param region
* The region used to allocate TypeLayout.
*
* \param opaqueClazz
* Class of the type whose layout needs to be populated.
*
* \return
* Returns a pointer to the TypeLayout object populated.
*/
const TR::TypeLayout* enumerateFields(TR::Region& region, TR_OpaqueClassBlock * clazz, TR::Compilation *comp);

uintptrj_t getArrayElementWidthInBytes(TR::Compilation *comp, TR_OpaqueClassBlock* arrayClass);

uintptrj_t persistentClassPointerFromClassPointer(TR::Compilation *comp, TR_OpaqueClassBlock *clazz);
Expand Down

0 comments on commit 0cab97e

Please sign in to comment.