Giter Club home page Giter Club logo

Comments (20)

pirunxi avatar pirunxi commented on August 25, 2024 1

已经确信并且修复了问题4,更新 hybridclr代码即可。

from hybridclr.

AlanLiu90 avatar AlanLiu90 commented on August 25, 2024

测试了hybridclr_trial+1.0分支没问题,比较了下数据,发现两个分支的ABinstance_sizefield offset不完全相同,而1.0分支和AOT版本的instance_sizefield offset是相同的。

怀疑是这次改动导致了问题:d14cfba

from hybridclr.

pirunxi avatar pirunxi commented on August 25, 2024

我们晚些时候解决这个问题。

from hybridclr.

pirunxi avatar pirunxi commented on August 25, 2024

我们修复了1和2,不过3和4没在测试工程复现,难道是必须在trial中才能复现?

from hybridclr.

AlanLiu90 avatar AlanLiu90 commented on August 25, 2024

3和4都是在dhe_demo中复现的。

from hybridclr.

AlanLiu90 avatar AlanLiu90 commented on August 25, 2024

我对比了下ClassFieldLayoutCalculator.cpp中的改动和IL2CPP的代码,发现有些不同,请看下是否有问题。

HybridCLR:

if (IsValueType(parentType))
{
	aligment = 1;
	parentActualSize = 0;
}
else
{
	CalcClassNotStaticFields(parentType);
	ClassLayoutInfo* parentLayout = GetClassLayoutInfo(parentType);
	parentActualSize = parentLayout->actualSize;
	aligment = PTR_SIZE;
}

IL2CPP:

if (klass->valuetype)
	klass->minimumAlignment = 1;
else
	klass->minimumAlignment = klass->parent->minimumAlignment;

有2个不同:

  1. IL2CPP是判断本类型是否是值类型,HybridCLR是用父类型判断
  2. IL2CPP引用类型的最小对齐初始值使用了父类的值,HybridCLR使用了指针大小

我刚才更新了代码,在项目中测试,崩溃了,把第1点改成IL2CPP那样,就正常了

from hybridclr.

pirunxi avatar pirunxi commented on August 25, 2024

改的时候看到了,大略思考一下,觉得这么改也行。不过确实是有瑕疵的,我们接着修复它。对于这个字段offset的问题,直接加入字段偏移的测试用例确保计算正确性。

from hybridclr.

pirunxi avatar pirunxi commented on August 25, 2024

已经修复提交了,测试用例中计算的offset与aot是一致的

from hybridclr.

AlanLiu90 avatar AlanLiu90 commented on August 25, 2024

更新到最新代码,还是会崩溃。看到还是用父类型判断是否是值类型:

const Il2CppType* parentType = il2cpp::vm::GlobalMetadata::GetIl2CppTypeFromIndex(typeDef->parentIndex);
if (IsValueType(parentType))   // <-------
{
	// ...
}

from hybridclr.

pirunxi avatar pirunxi commented on August 25, 2024

能否告诉我们什么样的测试代码下会崩溃?这代码确实是错的,但测试用例上未崩溃。

from hybridclr.

pirunxi avatar pirunxi commented on August 25, 2024

我们重新修复提交了

from hybridclr.

AlanLiu90 avatar AlanLiu90 commented on August 25, 2024

以下代码配合json文件可以在dhe_demo中复现那个用parentType判断导致的崩溃:

public enum EntityType
{
    Character,
}

public partial class EntityInfo
{
    public int Id;
    public EntityType EntityType;
    public string Name;
    public int A1;       
    public string A2;
    public string A3;
    public bool A4;  
    public string A5;
    public bool A6 = false;   
    public int A7 = 1;  

    public int A8 = 0;       

    public bool A9;
    public float A10;
}

[Serializable]
public partial class CharacterInfo: EntityInfo
{
    public float C1 = 1;
    public bool C2 = true;
    public Vector3 C3;
    public int[] C4;
    public List<int> C5;
}

[Serializable]
public partial class Character2Info : CharacterInfo
{
    public Character2Info()
    {
        EntityType = EntityType.Character;
    }

    public int E1;
    public int E2 = 1;
    
    public int E3 = 2;
}

class Case20
{
    public static void Run()
    {
        var text = File.ReadAllText(Path.Combine(Application.streamingAssetsPath, "test.txt"));
        var obj = (Character2Info)JsonUtility.FromJson(text, typeof(Character2Info));
        UnityEngine.Debug.Log(obj.Id + " " + obj.E3);
    }
}

json文件,需要放在StreamingAssets中:

test.txt

from hybridclr.

AlanLiu90 avatar AlanLiu90 commented on August 25, 2024

DHE的分支没有提交修复parentType的那个改动。我本地合并了main分支的改动进行测试,不会崩溃了。

from hybridclr.

pirunxi avatar pirunxi commented on August 25, 2024

感谢,我们刚更新了DHE。

from hybridclr.

pirunxi avatar pirunxi commented on August 25, 2024

问题3确认并且修复了。 未在测试工程复现的原因是 System.Activator.CreateInstance被补充了元数据,导致调用了解释器版本而未崩溃。

from hybridclr.

pirunxi avatar pirunxi commented on August 25, 2024

问题4没再复现。可能是hybridclr_unity计算桥接函数时加入DHE程序集后,不再出现缺失现象。

from hybridclr.

AlanLiu90 avatar AlanLiu90 commented on August 25, 2024

测试了下问题3的修复,有2个问题:

  • dheContext没有被使用
  • 新增代码的后面代码中,对newMethod->methodPointerCallByInterp进行赋值的地方,仍然使用了gmethod->context,还是会找不到实现

from hybridclr.

AlanLiu90 avatar AlanLiu90 commented on August 25, 2024

问题4使用最新的代码,在dhe_demo中测试,仍然存在。

对比了IL2CPP的代码,发现逻辑有些不同:

  • IL2CPP中,对于值类型的函数,先调用MetadataCache::GetAdjustorThunk,如果没找到,再调用MetadataCache::GetMethodPointer(值类型的静态函数不是adjustorThunk?)
  • HybridCLR中,先调用MetadataCache::GetAdjustorThunk,其中如果没在DHE Assembly中找到aotAdjustorThunk,就去桥接函数中找了

看起来应该在去找桥接函数之前,先尝试从DHE Assembly中的MethodPointer中查找?

from hybridclr.

pirunxi avatar pirunxi commented on August 25, 2024

问题3,我们修复了2020版本的问题。对于问题4,仍然无法复现。

另外IL2Cpp这部分逻辑是有瑕疵的,如果是类非静态成员函数,必然只能从AdjustorThunk里找,我们这是刻意这么实现的。

from hybridclr.

AlanLiu90 avatar AlanLiu90 commented on August 25, 2024

测试了关于问题3的新的修复,正常了。

我把Unity工程(2020.3.33)打包了,请看下能不能复现问题4?
dhe_demo_issue4.zip

from hybridclr.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.