Runtime (I)

Time:2022-5-24

Objective-C is a highly dynamic programming language, which is very different from C, C + + and other languages. The function call of Object-C is not determined at compile time, but at run time. The dynamic nature of Objective-C is supported by the runtime API. The interfaces provided by the runtime API are basically C language, and the source code is written in C \ C + + \ assembly language.

Detailed explanation of ISA

Before the arm64 architecture, ISA was an ordinary pointer that stored the memory addresses of class and meta class objects. Starting from the arm64 architecture, ISA was optimized into a union structure and used bit fields to store more information

Runtime (I)

isa_t
Isa bit field

nonpointer

0, which represents an ordinary pointer and stores the memory addresses of class and meta class objects
1. It means that it has been optimized and uses the bit field to store more information

has_assoc

Has the associated object been set? If not, it will release faster

has_cxx_dtor

Is there a C + + destructor (. Cxx_destruct)? If not, it will release faster

shiftcls

It stores the memory address information of class and meta class objects

magic

Used to distinguish whether the object has not completed initialization during debugging

weakly_referenced

Has it been pointed by a weak reference? If not, it will release faster

deallocating

Is the object being released

extra_rc

The value stored inside is the reference counter minus 1

has_sidetable_rc

Is the reference counter too large to store in ISA
If it is 1, the reference count is stored in the attribute of a class called sidetable

Class structure

The essence of class is an objc_ Class structure, which contains the structure that points to the original classClass isaPointer to the parent classClass superclassPointer, cache method listcache_t cache, class informationclass_data_bits_t bitsbits & FAST_DATA_MASKobtainclass_rw_tStructure, class_ rw_ T structure containsmethod_list_t * methodsMethod listproperty_list_t * propertiesAttribute listconst protocol_list_t * protocolsAnd other information, and also contains a special structure pointerconst class_ro_tclass_ ro_ T is the original class information of the class. It is a read-only structure, including the initial class name, member variable class label, method list, protocol list and other information.
Initialize class_ rw_ T structure will be_ ro_ Copy the method list, protocol list and other information in the T structure to class_ rw_ In the T structure, the attributes and methods added through runtime are also added to class_ rw_ T structure.

Runtime (I)

objc_class
Runtime (I)

class_rw_t.png
Runtime (I)

class_ro_t.png

class_ rw_ The methods, properties and protocols in T are two-dimensional arrays, which are readable and writable, including the initial content and classification content of the class

Runtime (I)

class_rw_t_detail

class_ ro_ Basemethodlist, baseprotocols, Ivars and baseproperties in T are one-dimensional arrays, which are read-only and contain the initial contents of the class

Runtime (I)

class_ro_t_detail

method_ T structure is the encapsulation of methods \ functions, includingSEL name const char * types IMP imp

Runtime (I)

method_t
  • Concrete implementation of IMP representative function
  • SEL stands for method \ function name, which is generally called selector. The underlying structure is similar to char *, which can be accessed through @ selector() and sel_ Registername(), which can be obtained through sel_ Getname() and nsstringfromselector() are converted into strings. For methods with the same name in different classes, the corresponding method selectors are the same
  • Types contains the function return value, parameter encoding string

Recommended Today

redis jedis application

package com.xzit.test; import lombok.extern.slf4j.Slf4j; import redis.clients.jedis.Jedis; import java.util.List; import java.util.Set; //1. Use jedis to complete the New Year's Day annual meeting lottery system (refer to the second day's case) @Slf4j(topic = “c.Reward”) public class Reward { public static void main(String[] args) { Jedis jedis = new Jedis(“192.168.44.4″,6379); //s_add(jedis,”cj001”, “user:1001”, “user:1002”, “user:1003”, “user:1004″); s_pop(jedis,”cj001”,1); } public […]