看jvm源码的时候怎么也看不懂,来回看了几次了就是关于iload 6 指令的解析

def(Bytecodes::_lload               , ubcp|____|____|____, vtos, ltos, lload               ,  _           );

看重载的def函数

  const char _    = ' ';
const int ____ = 0;

其中的_ 是上面的定义

void TemplateTable::def(Bytecodes::Code code, int flags, TosState in, TosState out, void (*gen)(), char filler) {
assert(filler == ' ', "just checkin'");
def(code, flags, in, out, (Template::generator)gen, 0);
}
//下面对应的有参函数 对应上面的无参函数 void TemplateTable::def(Bytecodes::Code code, int flags, TosState in, TosState out, void (*gen)(int arg), int arg) {
// should factor out these constants
const int ubcp = 1 << Template::uses_bcp_bit;
const int disp = 1 << Template::does_dispatch_bit;
const int clvm = 1 << Template::calls_vm_bit;
const int iswd = 1 << Template::wide_bit;
// determine which table to use
bool is_wide = (flags & iswd) != 0;
// make sure that wide instructions have a vtos entry point
// (since they are executed extremely rarely, it doesn't pay out to have an
// extra set of 5 dispatch tables for the wide instructions - for simplicity
// they all go with one table)
assert(in == vtos || !is_wide, "wide instructions have vtos entry point only");
Template* t = is_wide ? template_for_wide(code) : template_for(code);
// setup entry
t->initialize(flags, in, out, gen, arg);
assert(t->bytecode() == code, "just checkin'");
}

上面没有什么能明白调用了无参的gen()函数,那么就是

void TemplateTable::iload() {
transition(vtos, itos);
if (RewriteFrequentPairs) {
Label rewrite, done; // get next byte
__ load_unsigned_byte(rbx, at_bcp(Bytecodes::length_for(Bytecodes::_iload)));
// if _iload, wait to rewrite to iload2. We only want to rewrite the
// last two iloads in a pair. Comparing against fast_iload means that
// the next bytecode is neither an iload or a caload, and therefore
// an iload pair.
__ cmpl(rbx, Bytecodes::_iload);
__ jcc(Assembler::equal, done); __ cmpl(rbx, Bytecodes::_fast_iload);
__ movl(rcx, Bytecodes::_fast_iload2);
__ jccb(Assembler::equal, rewrite); // if _caload, rewrite to fast_icaload
__ cmpl(rbx, Bytecodes::_caload);
__ movl(rcx, Bytecodes::_fast_icaload);
__ jccb(Assembler::equal, rewrite); // rewrite so iload doesn't check again.
__ movl(rcx, Bytecodes::_fast_iload); // rewrite
// rcx: fast bytecode
__ bind(rewrite);
patch_bytecode(Bytecodes::_iload, rcx, rbx, false);
__ bind(done);
} //以上忽略 // Get the local value into tos
locals_index(rbx);
__ movl(rax, iaddress(rbx));
}

接下来

void TemplateTable::locals_index(Register reg, int offset) {
__ load_unsigned_byte(reg, at_bcp(offset));
__ negptr(reg);
}

我开始找 locals_index() 函数,只有这个两个参数的,以为有重载,结果没有,然后查资料说是有,可以省略参数,就将0作为默认参数,就不需要写这个0了

locals_index(rbx,0)

但是逻辑不符合,应该是 locals_index(rbx,1)才对

于是又发现在hpp文件中有一个定义

  static void locals_index(Register reg, int offset = 1);

莫非这个意思是设置默认值,然后省略了 1  ?

在本地做了实验

main.hpp

#ifndef UNTITLED2_MAIN_H
#define UNTITLED2_MAIN_H #endif //UNTITLED2_MAIN_H
static void locals_index(int reg, int offset = 1); main.cpp #include<stdio.h>
#include "main.h" int main(int argc, char* argv[]){ locals_index(1);
return 0;
} void locals_index(int reg, int offset){
printf("c=%d\n",reg+offset);
} //控制台打印
C:\Users\meto\CLionProjects\untitled2\cmake-build-debug\untitled2.exe
c=2 Process finished with exit code 0

果然是这个样子,说明了c++有默认值的用法

小c佳,你这样子不好,让我好一顿找

C++ 定义默认值void locals_index(int reg, int offset = 1);的更多相关文章

  1. [水煮 ASP.NET Web API2 方法论](3-3)路由默认值

    问题 如何为路由中参数设置默认值. 解决方案 不管使用属性路由还是集中式路由,ASP.NET WEB API 都可以很方便的为路由定义默认参数.在每次客户端请求的时候,如果客户端没有传这些参数,框架会 ...

  2. 【C#基础概念】函数参数默认值和指定传参和方法参数

    函数参数默认值和指定传参 最近在编写代码时发现介绍C#参数默认值不能像PL/SQL那样直接设置default,网上也没有太多详细的资料,自己琢磨并试验后整理成果如下: C#允许在函数声明部分定义默认值 ...

  3. java 8种基本数据类型的默认值及所占字节数

    通过一段代码来测试一下 8种基本数据类型的默认值 package dierge; public class Ceshi { int a; double b; boolean c; char d; fl ...

  4. java中8种数据类型和默认值所占字节数

    java 8种基本数据类型的默认值及所占字节数 通过一段代码来测试一下 8种基本数据类型的默认值 1 package dierge; 2 3 public class Ceshi { 4 int a; ...

  5. js中function参数默认值

    --在dreamweaver做网站时,函数定义是在一个*.js文件中,其中定义了一个func,有四个参数,function func(string1,url,flag,icon),然后在另一个asp中 ...

  6. sql的基本用法-------修改字段默认值和属性

    修改表中已有的字段属性 ALTER TABLE 表名 ALTER COLUMN 字段名 varchar(500) --sqlserver建表表时设置字段的默认值 create table 表(id i ...

  7. C# 3.0 { get; set; } 默认值

    .NET Framework 3.5 使用的是 C# 3.0,C# 3.0 有一些新的语言特性,其中有一项就是快捷属性. 之前的写法: private int _id = 0;public int I ...

  8. JS中给函数参数添加默认值

    最近在Codewars上面看到一道很好的题目,要求用JS写一个函数defaultArguments,用来给指定的函数的某些参数添加默认值.举例来说就是: // foo函数有一个参数,名为x var f ...

  9. SQL Server 删除表的默认值约束

    首先查出字段的默认值约束名称,然后根据默认值约束名称删除默认值约束 ) select @constraintName = b.name from syscolumns a,sysobjects b w ...

随机推荐

  1. 一次SQL查询优化原理分析(900W+数据,从17s到300ms)

    有一张财务流水表,未分库分表,目前的数据量为9555695,分页查询使用到了limit,优化之前的查询耗时16 s 938 ms (execution: 16 s 831 ms, fetching: ...

  2. 【题解】SOFTWARE 二分+搜索/dp

    题目描述 一个软件开发公司同时要开发两个软件,并且要同时交付给用户,现在公司为了尽快完成这一任务,将每个软件划分成m个模块,由公司里的技术人员分工完成,每个技术人员完成同一软件的不同模块的所用的天数是 ...

  3. [UWP] WinUI 2.6 使用指南

    2021年6月24日,Windows 11 正式对外发布,对于UWP开发者来说,这一天同样值得纪念,因为WinUI 2.6也正式发布了! 相同的时间点意味着一件事,即WinUI 2.6和Windows ...

  4. .NET Core/.NET5/.NET6 开源项目汇总9:客户端跨平台UI框架

    系列目录     [已更新最新开发文章,点击查看详细] .NET Core 实现了跨平台,支持在 Windwos.Linux.macOS上开发与部署,但是也仅限于Web应用程序.对于Windows桌面 ...

  5. Python3中最常用的5种线程锁你会用吗

    前言 本章节将继续围绕threading模块讲解,基本上是纯理论偏多. 对于日常开发者来讲很少会使用到本章节的内容,但是对框架作者等是必备知识,同时也是高频的面试常见问题. 官方文档 线程安全 线程安 ...

  6. excel VBA数组运用

    Sub a()Dim i人数 As Integer'定义变量Dim i考试成绩() As Integer'定义数组Dim i As Integer'定义变量i人数 = InputBox("输 ...

  7. 试着给VuePress添加全局禁止爬取支持,基于vuepress-plugin-robots

    背景 有时候,我们有些内部网站希望不被外部抓取,那么我们可以借助vuepress-plugin-robots来生成robots.txt文件,来告诉爬虫不要抓取页面. 安装 npm install vu ...

  8. redis字典快速映射+hash釜底抽薪+渐进式rehash | redis为什么那么快

    前言 相信你一定使用过新华字典吧!小时候不会读的字都是通过字典去查找的.在Redis中也存在相同功能叫做字典又称为符号表!是一种保存键值对的抽象数据结构 本篇仍然定位在[redis前传]系列中,因为本 ...

  9. Redis的主从数据一致性

    我们学习了 AOF 和 RDB,如果 Redis 发生了宕机,它们可以分别通过回放日志和重新读入 RDB 文件的方式恢复数据,从而保证尽量少丢失数据,提升可靠性.不过,即使用了这两种方法,也依然存在服 ...

  10. 关于tinymce的一些记事

    之前能看的懂一部分英文,但是总是没有全局观,以至于我之前使用tinymce一直都有一些疑问:那就是为什么我在tinymce初始化中添加了比如字体,字体大小等设置按钮,但是为什么在前 台没有办法现实出来 ...