Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit4a9bcb4

Browse files
committed
cleanup marshaling - dont' use ctx as a flag
1 parent0d927b6 commit4a9bcb4

File tree

3 files changed

+47
-23
lines changed

3 files changed

+47
-23
lines changed

‎src/mono/mono/metadata/marshal-lightweight.c‎

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2266,7 +2266,7 @@ emit_array_accessor_wrapper_ilgen (MonoMethodBuilder *mb, MonoMethod *method, Mo
22662266
}
22672267

22682268
staticvoid
2269-
emit_unsafe_accessor_field_wrapper (MonoMethodBuilder*mb,MonoMethod*accessor_method,MonoMethodSignature*sig,MonoGenericContext*ctx,MonoUnsafeAccessorKindkind,constchar*member_name)
2269+
emit_unsafe_accessor_field_wrapper (MonoMethodBuilder*mb,MonoMethod*accessor_method,MonoMethodSignature*sig,MonoUnsafeAccessorKindkind,constchar*member_name)
22702270
{
22712271
// Field access requires a single argument for target type and a return type.
22722272
g_assert (kind==MONO_UNSAFE_ACCESSOR_FIELD||kind==MONO_UNSAFE_ACCESSOR_STATIC_FIELD);
@@ -2315,7 +2315,7 @@ emit_unsafe_accessor_field_wrapper (MonoMethodBuilder *mb, MonoMethod *accessor_
23152315
* of the expected member method (ie, with the first arg removed)
23162316
*/
23172317
staticMonoMethodSignature*
2318-
method_sig_from_accessor_sig (MonoMethodBuilder*mb,gbooleanhasthis,MonoMethodSignature*accessor_sig,MonoGenericContext*ctx)
2318+
method_sig_from_accessor_sig (MonoMethodBuilder*mb,gbooleanhasthis,MonoMethodSignature*accessor_sig)
23192319
{
23202320
MonoMethodSignature*ret=mono_metadata_signature_dup_full (get_method_image (mb->method),accessor_sig);
23212321
g_assert (ret->param_count>0);
@@ -2332,7 +2332,7 @@ method_sig_from_accessor_sig (MonoMethodBuilder *mb, gboolean hasthis, MonoMetho
23322332
* of the expected constructor method (same args, but return type is void).
23332333
*/
23342334
staticMonoMethodSignature*
2335-
ctor_sig_from_accessor_sig (MonoMethodBuilder*mb,MonoMethodSignature*accessor_sig,MonoGenericContext*ctx)
2335+
ctor_sig_from_accessor_sig (MonoMethodBuilder*mb,MonoMethodSignature*accessor_sig)
23362336
{
23372337
MonoMethodSignature*ret=mono_metadata_signature_dup_full (get_method_image (mb->method),accessor_sig);
23382338
ret->hasthis= TRUE;/* ctors are considered instance methods */
@@ -2410,7 +2410,7 @@ inflate_method (MonoClass *klass, MonoMethod *method, MonoMethod *accessor_metho
24102410
}
24112411

24122412
staticvoid
2413-
emit_unsafe_accessor_ctor_wrapper (MonoMethodBuilder*mb,MonoMethod*accessor_method,MonoMethodSignature*sig,MonoGenericContext*ctx,MonoUnsafeAccessorKindkind,constchar*member_name)
2413+
emit_unsafe_accessor_ctor_wrapper (MonoMethodBuilder*mb,MonoMethod*accessor_method,MonoMethodSignature*sig,MonoUnsafeAccessorKindkind,constchar*member_name)
24142414
{
24152415
g_assert (kind==MONO_UNSAFE_ACCESSOR_CTOR);
24162416
// null or empty string member name is ok for a constructor
@@ -2434,7 +2434,7 @@ emit_unsafe_accessor_ctor_wrapper (MonoMethodBuilder *mb, MonoMethod *accessor_m
24342434
sig=update_signature(accessor_method);
24352435
}
24362436

2437-
MonoMethodSignature*member_sig=ctor_sig_from_accessor_sig (mb,sig,ctx);
2437+
MonoMethodSignature*member_sig=ctor_sig_from_accessor_sig (mb,sig);
24382438

24392439
MonoClass*in_class=mono_class_get_generic_type_definition (target_class);
24402440

@@ -2459,7 +2459,7 @@ emit_unsafe_accessor_ctor_wrapper (MonoMethodBuilder *mb, MonoMethod *accessor_m
24592459
}
24602460

24612461
staticvoid
2462-
emit_unsafe_accessor_method_wrapper (MonoMethodBuilder*mb,MonoMethod*accessor_method,MonoMethodSignature*sig,MonoGenericContext*ctx,MonoUnsafeAccessorKindkind,constchar*member_name)
2462+
emit_unsafe_accessor_method_wrapper (MonoMethodBuilder*mb,MonoMethod*accessor_method,MonoMethodSignature*sig,MonoUnsafeAccessorKindkind,constchar*member_name)
24632463
{
24642464
g_assert (kind==MONO_UNSAFE_ACCESSOR_METHOD||kind==MONO_UNSAFE_ACCESSOR_STATIC_METHOD);
24652465
g_assert (member_name!=NULL);
@@ -2486,7 +2486,7 @@ emit_unsafe_accessor_method_wrapper (MonoMethodBuilder *mb, MonoMethod *accessor
24862486
sig=update_signature(accessor_method);
24872487
}
24882488

2489-
MonoMethodSignature*member_sig=method_sig_from_accessor_sig (mb,hasthis,sig,ctx);
2489+
MonoMethodSignature*member_sig=method_sig_from_accessor_sig (mb,hasthis,sig);
24902490

24912491
MonoClass*in_class=mono_class_get_generic_type_definition (target_class);
24922492

@@ -2520,9 +2520,14 @@ emit_unsafe_accessor_method_wrapper (MonoMethodBuilder *mb, MonoMethod *accessor
25202520
}
25212521

25222522
staticvoid
2523-
emit_unsafe_accessor_wrapper_ilgen (MonoMethodBuilder*mb,MonoMethod*accessor_method,MonoMethodSignature*sig,MonoGenericContext*ctx,MonoUnsafeAccessorKindkind,constchar*member_name)
2523+
emit_unsafe_accessor_wrapper_ilgen (MonoMethodBuilder*mb,MonoMethod*accessor_method,MonoMethodSignature*sig,gbooleanto_be_inflated,MonoUnsafeAccessorKindkind,constchar*member_name)
25242524
{
2525-
if (accessor_method->is_generic||ctx!=NULL) {
2525+
// to_be_inflated means we're emitting a non-generic accessor method belonging to a gtd
2526+
// that will be inflated by marshal.c
2527+
if (to_be_inflated)
2528+
g_assert (!accessor_method->is_inflated&& !accessor_method->is_generic);
2529+
2530+
if (accessor_method->is_generic||to_be_inflated) {
25262531
mono_mb_emit_exception_full (mb,"System","BadImageFormatException","UnsafeAccessor_Generics");
25272532
return;
25282533
}
@@ -2535,14 +2540,14 @@ emit_unsafe_accessor_wrapper_ilgen (MonoMethodBuilder *mb, MonoMethod *accessor_
25352540
switch (kind) {
25362541
caseMONO_UNSAFE_ACCESSOR_FIELD:
25372542
caseMONO_UNSAFE_ACCESSOR_STATIC_FIELD:
2538-
emit_unsafe_accessor_field_wrapper (mb,accessor_method,sig,ctx,kind,member_name);
2543+
emit_unsafe_accessor_field_wrapper (mb,accessor_method,sig,kind,member_name);
25392544
return;
25402545
caseMONO_UNSAFE_ACCESSOR_CTOR:
2541-
emit_unsafe_accessor_ctor_wrapper (mb,accessor_method,sig,ctx,kind,member_name);
2546+
emit_unsafe_accessor_ctor_wrapper (mb,accessor_method,sig,kind,member_name);
25422547
return;
25432548
caseMONO_UNSAFE_ACCESSOR_METHOD:
25442549
caseMONO_UNSAFE_ACCESSOR_STATIC_METHOD:
2545-
emit_unsafe_accessor_method_wrapper (mb,accessor_method,sig,ctx,kind,member_name);
2550+
emit_unsafe_accessor_method_wrapper (mb,accessor_method,sig,kind,member_name);
25462551
return;
25472552
default:
25482553
mono_mb_emit_exception_full (mb,"System","BadImageFormatException","UnsafeAccessor_InvalidKindValue");

‎src/mono/mono/metadata/marshal.c‎

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5230,20 +5230,25 @@ mono_marshal_get_unsafe_accessor_wrapper (MonoMethod *accessor_method, MonoUnsaf
52305230
MonoMethod*orig_method=NULL;
52315231
WrapperInfo*info;
52325232
gbooleanis_generic= FALSE;
5233+
gbooleanis_inflated= FALSE;
52335234

52345235
if (member_name==NULL&&kind!=MONO_UNSAFE_ACCESSOR_CTOR)
52355236
member_name=accessor_method->name;
52365237

5238+
printf("CAME IN: %s (generic = %d, inflated = %d)\n",mono_method_full_name(accessor_method, TRUE),accessor_method->is_generic?1:0,accessor_method->is_inflated?1:0);
5239+
52375240
if (accessor_method->is_generic) {
52385241
// FullAOT compilation with gshared or gsharedvt will get here.
52395242
/* got a generic method definition. need to make a generic method definition wrapper */
52405243
g_assert (!accessor_method->is_inflated);
52415244
is_generic= TRUE;
5242-
}
5245+
}elseif (accessor_method->is_inflated) {
5246+
// FIXME: this always tries to compile a generic version of the accessor method and
5247+
// then inflate it. But maybe we dont' want to do that (particularly for field
5248+
// accessors). In particular if there is no method_inst, we're looking at an
5249+
// accessor method inside a generic class (alwayst a ginst? or sometimes a gtd?)
5250+
// In that case we might just want to compile the instance.
52435251

5244-
/* FIXME: Support generic methods too */
5245-
if (accessor_method->is_inflated) {
5246-
// non-full AOT may get here
52475252
g_assert (!is_generic);
52485253
orig_method=accessor_method;
52495254
ctx=&((MonoMethodInflated*)accessor_method)->context;
@@ -5252,13 +5257,21 @@ mono_marshal_get_unsafe_accessor_wrapper (MonoMethod *accessor_method, MonoUnsaf
52525257
if (!container)
52535258
container=mono_class_try_get_generic_container (accessor_method->klass);//FIXME is this a case of a try?
52545259
g_assert (container);
5260+
is_inflated= TRUE;
52555261
}
52565262

5263+
printf("work on: %s (generic = %d, inflated = %d)\n",mono_method_full_name(accessor_method, TRUE),accessor_method->is_generic?1:0,accessor_method->is_inflated?1:0);
5264+
5265+
/*
5266+
* the method is either a generic method definition, or it might be inflated, not both at
5267+
* the same time.
5268+
*/
5269+
g_assert (!(is_generic&&is_inflated));
5270+
52575271
/*
52585272
* Check cache
52595273
*/
5260-
if (ctx) {
5261-
/* FIXME get the right cache */
5274+
if (is_inflated) {
52625275
cache=get_cache (&((MonoMethodInflated*)orig_method)->owner->wrapper_caches.unsafe_accessor_cache ,mono_aligned_addr_hash,NULL);
52635276
res=check_generic_wrapper_cache (cache,orig_method,orig_method,accessor_method);
52645277
if (res)
@@ -5268,10 +5281,13 @@ mono_marshal_get_unsafe_accessor_wrapper (MonoMethod *accessor_method, MonoUnsaf
52685281
if ((res=mono_marshal_find_in_cache (cache,accessor_method)))
52695282
returnres;
52705283
}
5271-
5272-
5284+
printf ("Cache miss\n");
5285+
52735286
mb=mono_mb_new (accessor_method->klass,accessor_method->name,MONO_WRAPPER_OTHER);
52745287
if (is_generic) {
5288+
// If the accessor method was generic, make the wrapper generic, too.
5289+
5290+
// Load a copy of the generic params of the accessor method
52755291
mb->method->is_generic=is_generic;
52765292
container=mono_class_try_get_generic_container (accessor_method->klass);
52775293
container=mono_metadata_load_generic_params (m_class_get_image (accessor_method->klass),accessor_method->token,container,/*owner:*/mb->method);
@@ -5281,6 +5297,8 @@ mono_marshal_get_unsafe_accessor_wrapper (MonoMethod *accessor_method, MonoUnsaf
52815297
inst_ctx.method_inst=container->context.method_inst;
52825298

52835299
ERROR_DECL (error);
5300+
// make a copy of the accessor signature, but replace the params of the accessor
5301+
// method, by the params we just loaded
52845302
sig=mono_inflate_generic_signature (mono_method_signature_internal (accessor_method),&inst_ctx,error);
52855303
mono_error_assert_ok (error);// FIXME
52865304
}else {
@@ -5291,14 +5309,15 @@ mono_marshal_get_unsafe_accessor_wrapper (MonoMethod *accessor_method, MonoUnsaf
52915309
get_marshal_cb ()->mb_skip_visibility (mb);
52925310

52935311
// TODO: pass container, too
5294-
get_marshal_cb ()->emit_unsafe_accessor_wrapper (mb,accessor_method,sig,ctx,kind,member_name);
5312+
// TODO: passing the ctx is not super useful because accessor_method is always the generic version of the method, even if is_inflated == TRUE. pass `is_inflated` instead
5313+
get_marshal_cb ()->emit_unsafe_accessor_wrapper (mb,accessor_method,sig,is_inflated,kind,member_name);
52955314

52965315
info=mono_wrapper_info_create (mb,WRAPPER_SUBTYPE_UNSAFE_ACCESSOR);
52975316
info->d.unsafe_accessor.method=accessor_method;
52985317
info->d.unsafe_accessor.kind=kind;
52995318
info->d.unsafe_accessor.member_name=member_name;
53005319

5301-
if (ctx) {
5320+
if (is_inflated) {
53025321
MonoMethod*def;
53035322
def=mono_mb_create_and_cache_full (cache,accessor_method,mb,sig,sig->param_count+16,info,NULL);
53045323
res=cache_generic_wrapper (cache,orig_method,def,ctx,orig_method);

‎src/mono/mono/metadata/marshal.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@ typedef struct {
342342
void (*emit_synchronized_wrapper) (MonoMethodBuilder*mb,MonoMethod*method,MonoGenericContext*ctx,MonoGenericContainer*container,MonoMethod*enter_method,MonoMethod*exit_method,MonoMethod*gettypefromhandle_method);
343343
void (*emit_unbox_wrapper) (MonoMethodBuilder*mb,MonoMethod*method);
344344
void (*emit_array_accessor_wrapper) (MonoMethodBuilder*mb,MonoMethod*method,MonoMethodSignature*sig,MonoGenericContext*ctx);
345-
void (*emit_unsafe_accessor_wrapper) (MonoMethodBuilder*mb,MonoMethod*accessor_method,MonoMethodSignature*sig,MonoGenericContext*ctx,MonoUnsafeAccessorKindkind,constchar*member_name);
345+
void (*emit_unsafe_accessor_wrapper) (MonoMethodBuilder*mb,MonoMethod*accessor_method,MonoMethodSignature*sig,gbooleanto_be_inflated,MonoUnsafeAccessorKindkind,constchar*member_name);
346346
void (*emit_generic_array_helper) (MonoMethodBuilder*mb,MonoMethod*method,MonoMethodSignature*csig);
347347
void (*emit_thunk_invoke_wrapper) (MonoMethodBuilder*mb,MonoMethod*method,MonoMethodSignature*csig);
348348
void (*emit_create_string_hack) (MonoMethodBuilder*mb,MonoMethodSignature*csig,MonoMethod*res);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp