-
Notifications
You must be signed in to change notification settings - Fork 729
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[WIP] ConstantDynamic: Adds static and dynamic verification for ConDy #1631
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -217,6 +217,8 @@ checkBytecodeStructure (J9CfrClassFile * classfile, UDATA methodIndex, UDATA len | |
|
||
case CFR_BC_ldc: | ||
case CFR_BC_ldc_w: | ||
J9CfrConstantPoolInfo *constantDynamicNameAndSignature = NULL; | ||
|
||
if (bc == CFR_BC_ldc) { | ||
NEXT_U8(index, bcIndex); | ||
} else { | ||
|
@@ -231,6 +233,10 @@ checkBytecodeStructure (J9CfrClassFile * classfile, UDATA methodIndex, UDATA len | |
info = &(classfile->constantPool[index]); | ||
tag = (UDATA) info->tag; | ||
|
||
if (CFR_CONSTANT_Dynamic == tag) { | ||
constantDynamicNameAndSignature = &classFile->constantPool[classFile->constantPool[info].slot2]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
} | ||
|
||
if (!((tag == CFR_CONSTANT_Integer) | ||
|| (tag == CFR_CONSTANT_Float) | ||
|| (tag == CFR_CONSTANT_String) | ||
|
@@ -239,7 +245,13 @@ checkBytecodeStructure (J9CfrClassFile * classfile, UDATA methodIndex, UDATA len | |
|| ((flags & BCT_MajorClassFileVersionMask) == 0))) | ||
|| (((tag == CFR_CONSTANT_MethodType) || (tag == CFR_CONSTANT_MethodHandle)) | ||
&& (((flags & BCT_MajorClassFileVersionMask) >= BCT_Java7MajorVersionShifted) | ||
|| ((flags & BCT_MajorClassFileVersionMask) == 0))) )) { | ||
|| ((flags & BCT_MajorClassFileVersionMask) == 0))) | ||
|| ((tag == CFR_CONSTANT_Dynamic) | ||
&& (((flags & BCT_MajorClassFileVersionMask) >= BCT_Java11MajorVersionShifted) | ||
|| ((flags & BCT_MajorClassFileVersionMask) == 0)) | ||
&& ('D' != constantDynamicNameAndSignature->bytes[constantDynamicNameAndSignature->slot1 - 1]) | ||
&& ('J' != constantDynamicNameAndSignature->bytes[constantDynamicNameAndSignature->slot1 - 1])) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we should use a more informative error message, not just There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agreed, updating |
||
)) { | ||
errorType = J9NLS_CFR_ERR_BC_LDC_NOT_CONSTANT__ID; | ||
/* Jazz 82615: Set the constant pool index to show up in the error message framework */ | ||
errorDataIndex = index; | ||
|
@@ -248,6 +260,8 @@ checkBytecodeStructure (J9CfrClassFile * classfile, UDATA methodIndex, UDATA len | |
break; | ||
|
||
case CFR_BC_ldc2_w: | ||
J9CfrConstantPoolInfo *constantDynamicNameAndSignature = NULL; | ||
|
||
NEXT_U16(index, bcIndex); | ||
if ((!index) || (index >= cpCount - 1)) { | ||
errorType = J9NLS_CFR_ERR_BAD_INDEX__ID; | ||
|
@@ -257,8 +271,18 @@ checkBytecodeStructure (J9CfrClassFile * classfile, UDATA methodIndex, UDATA len | |
} | ||
info = &(classfile->constantPool[index]); | ||
tag = (UDATA) info->tag; | ||
|
||
if (CFR_CONSTANT_Dynamic == tag) { | ||
constantDynamicNameAndSignature = &classFile->constantPool[classFile->constantPool[info].slot2]; | ||
} | ||
if (!((tag == CFR_CONSTANT_Double) | ||
|| (tag == CFR_CONSTANT_Long))) { | ||
|| (tag == CFR_CONSTANT_Long) | ||
|| ((tag == CFR_CONSTANT_Dynamic) | ||
&& (((flags & BCT_MajorClassFileVersionMask) >= BCT_Java11MajorVersionShifted) | ||
|| ((flags & BCT_MajorClassFileVersionMask) == 0)) | ||
&& ('D' != constantDynamicNameAndSignature->bytes[constantDynamicNameAndSignature->slot1 - 1]) | ||
&& ('J' != constantDynamicNameAndSignature->bytes[constantDynamicNameAndSignature->slot1 - 1])) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should be |
||
)) { | ||
errorType = J9NLS_CFR_ERR_BC_LDC_NOT_CONSTANT__ID; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same with error message |
||
/* Jazz 82615: Set the constant pool index to show up in the error message framework */ | ||
errorDataIndex = index; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -396,7 +396,7 @@ initializeClassNameList(J9BytecodeVerificationData *verifyData) | |
|
||
|
||
UDATA * | ||
pushLdcType(J9ROMClass * romClass, UDATA index, UDATA * stackTop) | ||
pushLdcType(J9BytecodeVerificationData *verifyData, J9ROMClass * romClass, UDATA index, UDATA * stackTop) | ||
{ | ||
switch(J9_CP_TYPE(J9ROMCLASS_CPSHAPEDESCRIPTION(romClass), index)) { | ||
case J9CPTYPE_CLASS: | ||
|
@@ -417,6 +417,15 @@ pushLdcType(J9ROMClass * romClass, UDATA index, UDATA * stackTop) | |
case J9CPTYPE_METHODHANDLE: | ||
PUSH(BCV_JAVA_LANG_INVOKE_METHODHANDLE_INDEX << BCV_CLASS_INDEX_SHIFT); | ||
break; | ||
case J9CPTYPE_CONSTANT_DYNAMIC: | ||
J9ROMConstantDynamicRef* romConstantDynamicRef = (J9ROMConstantDynamicRef *)(J9_ROM_CP_FROM_ROM_CLASS(romClass) + index); | ||
J9UTF8 *nameAndSignature = J9ROMCONSTANTDYNAMICREF_NAMEANDSIGNATURE(romConstantDynamicRef); | ||
U_8* signature = J9UTF8_DATA(nameAndSignature); | ||
|
||
/* The return value of a method follows the first ')' listed in its signature */ | ||
while (*signature++ != ')'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. read the condy spec 4.4.13, it seem to suggest that the signature referenced in a ConstantDynamic entry is a fieldDescriptor, so there will be no I'll read the spec details to confirm this, may need to add more checks in static verify to consider cases such as double array signature There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Right, thanks. Looks like I could directly give the value of What situations istatic verify would/would not accept cases such as the double array signature
&
Quick reread of the section you pointed out gives: 4.4.13 gives:
4.4.6 gives:
4.3.2 gives the grammar for a field descriptor as:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Woops, you're right - sounds like I can put directly into I'm not seeing any restrictions on the type of the signature - references (including cases like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. your current check is checking at the last There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, but if it's a a fieldDescriptor, then can't we directly check the first index instead? |
||
pushType(verifyData, signature, stackTop); | ||
break; | ||
} | ||
|
||
return stackTop; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -452,7 +452,7 @@ pushFieldType(J9BytecodeVerificationData *verifyData, J9UTF8 * utf8string, UDATA | |
* @return UDATA * | ||
*/ | ||
UDATA * | ||
pushLdcType(J9ROMClass * romClass, UDATA index, UDATA * stackTop); | ||
pushLdcType(J9BytecodeVerificationData *verifyData, J9ROMClass * romClass, UDATA index, UDATA * stackTop); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can you update the description comments? |
||
|
||
|
||
/** | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2133,6 +2133,8 @@ typedef struct J9ConstantPool { | |
#define J9CPTYPE_INTERFACE_STATIC_METHOD 16 | ||
#define J9CPTYPE_INTERFACE_INSTANCE_METHOD 17 | ||
|
||
#define J9CPTYPE_CONSTANT_DYNAMIC 18 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is already defined in #1426, forgot to tell you, sry |
||
|
||
#define J9_CP_BITS_PER_DESCRIPTION 8 | ||
#define J9_CP_DESCRIPTIONS_PER_U32 4 | ||
#define J9_CP_DESCRIPTION_MASK 255 | ||
|
@@ -2239,6 +2241,8 @@ typedef struct J9ROMStringRef { | |
|
||
#define J9ROMSTRINGREF_UTF8DATA(base) NNSRP_GET((base)->utf8Data, struct J9UTF8*) | ||
|
||
#define J9ROMCONSTANTDYNAMICREF_NAMEANDSIGNATURE(base) NNSRP_GET((base)->nameAndSignature, struct J9UTF8*) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. apology for the error in my PR, this should be and you would access the field descriptor with |
||
|
||
typedef struct J9ROMFieldRef { | ||
U_32 classRefCPIndex; | ||
J9SRP nameAndSignature; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit pick, maybe
constantDynamicSignature
would be more reflective?